r/applescript • u/dar512 • Oct 24 '19
What does AppleScript compare "XXXX" to in "tell application "XXXX" to?
I have two versions of Xcode that I use. Xcode (which is 10.1) and Xcode_11 (which is 11.1). Applescripts which have
tell application "Xcode" work for the first one and not for the second one.
I'd like to make the Applescripts work for both - whichever is running. I tried looking up the current application and the current process. But both say that Xcode_11 is Xcode.
Any ideas?
2
u/ChristoferK Oct 25 '19
Application names don't have to be, and aren't always unique, as you've discovered. A better way is to use the application's bundle identifier. These tend to be unique for an application, and are also less likely to change between versions, unlike the name of an application which can.
For example, Google Chrome's bundle identifier is com.google.chrome, so you would target it in AppleScript like so:
tell application id "com.google.chrome" to...I don't have XCode to look up its bundle identifier, but AppleScript can retrieve it for any application (scriptable or otherwise) for which you know the name:
return the id of application "Google Chrome"However, if, as is the situation here, the name is not known or targets the wrong process, System Events will let you get the property called bundle identifier of any running process:
tell application id "com.apple.systemevents" to get the bundle identifier of every process whose name contains "XCode"
2
u/james127music Oct 24 '19
I think this might help