If I have 2 instances of one application running, and I want to target one of them by their PID to run an Applescript snippet, how would I go about that? I have the PID of the instance I want to target, but if I run the following, it will execute on whichever instance was started last.
tell application "/Applications/Adobe After Effects CC 2018/Adobe After Effects CC 2018.app" to DoScript "alert()"
Is there a way to either set an instance as the "Frontmost" so it get's targeted, or get an application by PID and tell that one specifically?
Thanks!
Best Answer
Scripting Bridge Approach
With ScriptingBridge, create an
SBApplication
instance with applicationWithProcessIdentifier: and then you can call the bridged AppleScript methods on the process of your choice.AppleScript Approach
A discussion on MacScripter suggests this approach:
See also: How to activate Mac OS X application with a given process ID?