Quantcast
Viewing all articles
Browse latest Browse all 2

Answer by user3439894 for Use highlighted file in Finder as Bash variable (Applescript, macOS 10.13)

There is more then one way to do it and also depends on how may Finderitems are selected. Here's an example if only one item is selected in Finder:

set theTarget to POSIX path of (application "Finder"'s selection as string)

Or, if the pathname has spaces, use:

set theTarget to quoted form of POSIX path of (application "Finder"'s selection as string)

Sans the shown examples, the other ways can depend on how/where it falls in the rest of your code and whether or not more then one item is selected in Finder, however this is a place to start.


BTW If you're doing this AppleScript from bash, not Script Editor where the other examples were run, then using osascript in bash to run the same exampleAppleScriptcode shown above, with a single item selected in Finder, it would be:

theTarget="$(osascript -e "POSIX path of (application \"Finder\"'s selection as string)")"

Or:

theTarget="$(osascript -e "quoted form of POSIX path of (application \"Finder\"'s selection as string)")"

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>