Copy Finder Selection Paths

Posted on January 29, 2013
Filed Under Applescript, Macro Programs | 2 Comments

I’m quite happy with my recent switch to Keyboard Maestro. I’ll do a full review soon. The following is a fairly obvious script I’m sure most of you use. It simply gets the quoted form of the paths for all the Finder selection and puts it on the clipboard. Since I primarily use this with the shell I separate the paths with a space. I had used this in Quickeys but in Keyboard Maestro I use it with Brent Tepstra’s hyper meta key. So for me it’s mapped to C, which is a variation of the copy key. (I never use copy and paste in the Finder so I could have overloaded those, but this is probably safer) 

I also put a related script as a Terminal text expansion for ]finder as I’m pretty sure that’s not something I’d type accidentally. I have an organizational setup where ;shortcut is for character expansions in Keyboard Maestro (i.e. no code running) and ]shortcut is for smarter expansion. It makes it a bit easier to tell at a glance what is going on. I had a bash function that did more or less the same thing but I kind of like this better for interactive use.

The following is the Applescript I use. I still hate Applescript of course but I’m reconciling myself to using it until (hopefully) Apple comes up with an alternative. This replaces an older Applescript I think I may have posted that was a little more convoluted to set the delimiters. 

You’ll note that this is a gist. I was looking at using git to store my scripts but I think for short ones using a gist is better. I know some really don’t like gists being used to display code in blogs. But I’ve not seen a better solution suggested by anyone and I’ve come to not like using pre tags due to some problems MarsEdit has handling them correctly. The one big downside to using a gist is that it really doesn’t format Applescript terribly well.

Here’s the script I use in the terminal to type the Finder selection paths.

Finally here’s my much code to type the path for the front Finder window much more simply than what I tried to do in Quickeys a couple of weeks ago. It’s pretty much the same as how Drang did it in his original post. (Which honestly was what drove me to switch to Keyboard Maestro)

Comments

2 Responses to “Copy Finder Selection Paths”
1 Christopher Stone on January 29th, 2013 5:19 pm

Just a bit more efficient.

In the Finder getting the selection ‘as alias list’ is far faster than getting Finder references.

tell application “Finder” to set theSel to selection as alias list
repeat with anItem in theSel
     set contents of anItem to quoted form of (POSIX path of anItem)
end repeat
set {oldTIDS, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, ” “}
set the clipboard to theSel as string
set AppleScript’s text item delimiters to oldTIDS

You can also transform the contents of items in a referenced list directly, and it’s quick.


Take Care,
Chris

Thanks. I didn’t know that. I updated my scripts with your suggestion.

Leave a Reply