passing current file path to a bash variable (via osascript)

Hello there

this is a basic question that I’m hoping someone here can help me with. I’ve got a bash script that needs to begin by getting the full path of the currently selected file in Finder.

So I want to use osascript to do something like:

bashFilePath=$(osascript -e 'tell application "Finder" to set filePath to path of item 1 of selection')

but this doesn’t work and I’ve no idea how to figure out what will, short of asking if anyone here knoweth…

Thanks in advance for your time.

  • padmavyuha

No experience with the shell, but this works here:

bashFilePath=$(osascript -e 'tell application "Finder" to set filePath to quoted form of posix path of (item 1 of (get selection) as text)');echo $bashFilePath;

many thanks! it’s always the brackets that get me…

  • padmavyuha