Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applescript path to application using variable

Tags:

applescript

If I have an applescript snippet such as this

tell application "Finder"
set thePath to (POSIX path of (path to application "MyApp"))
end tell

it will return to me

"/Applications/MyApp.app"

Now, what I can't seem to figure out is how to instead specify "MyApp" via a variable rather than the literal.

My applescript reads in some XML values, one of them being the name of the application I'm interesting in. I've tried this:

tell application "Finder"
set thePath to (POSIX path of (path to application someVariable))
end tell

but this simply tells me the error

"Finder got an error: Can't make application "MyApp" into type constant."

Any ideas how I can do this?

like image 372
itsmatt Avatar asked Mar 19 '26 02:03

itsmatt


1 Answers

The answer (or at least one answer) is:

set theApp to "MyApp"
set pathToTarget to POSIX path of (path to application theApp)

Since path to application is a part of Standard Additions, the Finder is not needed.

Thanks to Stephan K on MacScripter for setting me straight on this.

like image 145
itsmatt Avatar answered Mar 24 '26 11:03

itsmatt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!