Open file by application process ID (PID)
I am using shell commands in an Applescript to open multiple instances of an application.
How can I force a particular instance to open a file AFTER the instance is open?
I.e., the following is NOT what I am after, as this opens the file at the same time the instance is created:
do shell script "open -na preview.app " & quoted form of POSIX path of "myfile.pdf"
----------
If I just use an open command, the same instance always opens the file, regardless of which instance is frontmost. I've also used applescript to control the frontmost application's menus (File > Open), but that is slow and clumsy.
The only way I can think of is to use the process IDs of the instances. I've got the list of PIDs with this:
set the_pids to (do shell script "ps ax | grep " & "Preview" & " | grep -v grep | awk '{print $1}'")
but how can I now use a PID to open a file?