I've been wanting to do that too, however unlike the solutions above, I wanted to produce quoted parameters for a shell script. Those other methods are fine, but they're kind of like suggesting "just command-v into terminal" when what you really want is pbpaste
.
I wanted to make a shell function I can use in my scripts that expanded to file parameters for each Finder selection. I use the fish shell and this seems to work somewhat:
function selection
osascript -e "tell application \"Finder\" to set s to the selection as alias list" -e "repeat with f in s" -e "set contents of f to POSIX path of f" -e "end repeat" -e "set AppleScript's text item delimiters to linefeed" -e "s as string"
end
Used (again in the fish shell) like convert-video (selection)
.
In a bash function, it might need to quote the output with something like | tr '\n' '\0' | xargs -0 printf "%q" {}
on the end of that osascript command, not sure.
(note: everything i know about advanced applescript & shell scripting i re-learned in the past 2 hours and will forget by tomorrow)