I created an automator File/Folder service to copy the file path of a file/folder to the clipboad. I needed it to be formated in a specific way so that I can send links to fellow co-workers that will take them directly to the file.
Here’s how it was set up:
Automator service that receives files or folders in finder.
Run AppleScript Action:
(* this changes the Applescript path to a POSIX path *)
on run {input, parameters}
set newPath to (the POSIX path of input)
get replaceSpaces(" ", "%20", newPath)
end run
(* this replaces all spaces with "%20" and adds "file://" prefix so we can paste a clickable link on IM*)
on replaceSpaces(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs
return subject
end replaceSpaces
Another Run Applescript Action:
(* this changes the Applescript path to a POSIX path *)
on run {input, parameters}
set newPath to (the POSIX path of input)
get replaceXserve("xserve", "Volumes/Xsan", newPath)
end run
(* this replaces "xserve" to work on the edit stations *)
on replaceXserve(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs
set filePrefix to "file://"
return filePrefix & subject
end replaceXserve
Copy to Clipboard Action
This give me the path I’m looking for. Something like this:
file:///Volumes/Xsan/Production/Document.doc
Right now everything works but it can be sporadic. I think it might have something to do with running 2 “Run AppleScript” actions. Is there a way to streamline this script?
This seems like an extraordinary amount of work. Are you just trying to get the path of a file on your local machine for other Users to pick up (and yes, I understand the need for the conformity of the path for IM (though, I take it you’re not using iChat and dragging and dropping files to it?))?
if the path is valid, you can use System Events (or Finder) to get the file URL of the path, for example
set thePath to path to application support folder as text
tell application "System Events"
set theItem to item thePath
set theURL to URL of theItem
end tell
--> "file://localhost/Library/Application%20Support/"
tell application "Finder" to (set the clipboard to (URL of (selection as alias) as Unicode text))
Grab a file, trigger the script, done. (Unless I’m missing something.) And I think I am, since this returns a localhost reference and the file is remotely hosted. But some quick sed work could do a faster replacement of the localhost with the machine / Volume name.
In some ways this is “six of one, half a dozen of the other” since pulling the posix path is possible too but I would still opt for sed over delimiters to do the character replacements.
Yeah, I know. This was more proof of concept one-liner - but thanks.
Any selections in the Finder I always run through a repeat loop, even if it’s only one file selected, to eliminate this error.
I’m with stefan too, that’s the easiest solution but to make it more waterthight I would use this so you won’t get an error if there is no selection at all (the clipboard will be empty).
tell application "Finder" to set the clipboard to (URL of item 1 of (selection & {{URL:""}}) as Unicode text)
We have a huge server with lots of folders within folders. It’s just a lot easier to send direct paths to folks so that they can go straight to what they need. I notice this doesn’t work with AIM but works perfectly through Bonjour (And no we’re not sending the files just the link).
It works when I send a link in this format: file:///xserve/Production/Documents/Document%20with%20Spaces.txt
It might work with other formats too but I don’t know what it is. The other issue is that some of the workstations are connected through a different file system so their path would look like this: file:///Volume/Xsan/Production/Documents/Document%20with%20Spaces.txt
So I created 3 actions, one for sending paths to same file systems, one that goes Xserve > Xsan and one Xsan >Xserve. I want to install this on all the workstation so we can send links easily.
Sorry for the long winded explanation. What I have now seems to work but like you guys said I’m pretty sure I’m over doing it. I tried some of what was posted here but I couldn’t get it to work.
when trying something like this:
on run {input, parameters}
tell application "Finder" to (set the clipboard to (URL of (input as alias) as Unicode text))
end run
it returns:
(
)
I’m very new to scripting so If some one can explain to me more in depth what I need to do I would be grateful. Thanks again!