Skip to main content

How to get the selected item in Finder using AppleScript

I was doing some stuff today where I was selecting items in Finder, and then passing them to a command-line app in Terminal. I could drag-and-drop the files into Terminal to get their path, but for hundreds of items that gets tedious – I wanted a way for Terminal to automatically get the current item in Finder.

I found an AppleScript that does this:

tell application "Finder" to get POSIX path of first item of (selection as alias list)

Open questions if I decide to revisit this snippet: