I wanted the AppleScript form of a path to a selected file in a Finder window.
Dragging the file’s icon to the Script Editor window produces the full POSIX form: "/Users/… etc.
Telling the Finder to get the selection returns the {document file of folder “x” of folder “y” of …} form
Telling the Finder to ‘get POSIX path of ((get selection) as alias)’ [parentheses required] gets the same form as dragging the file did: full path of form "/Users/username/…etc.
Only this outrageous form will produce the colon form of the path to the file:
tell application "Finder" to get POSIX path of ((get selection) as alias) as string as POSIX file as string
which seems so convoluted that I expect there must be a better way. Tell me there is.
And for me too, Bruce. Can’t think now what I was screwing up. I kept getting errors of coercion and kept adding more stuff.
Thanks.
tell application "Finder" to set A to POSIX path of ((get selection) as alias)
tell application "Finder" to set b to selection as alias
tell application "Finder" to set c to selection as Unicode text
{A, b, c}
-- {
-- "/Applications/Chess.app/",
-- alias "MyHD:Applications:Chess.app:",
-- MyHD:Applications:Chess.app"
-- }
I do notice that the get selection as alias form produces a folder-type path for an app, while the other two identify .app.