javascript - How can one address two instances of the same application through osascript -


can think of workaround osascript index-by-name bottle-neck in reference multiple instances of same application ?

if obtain 2 process ids – 1 each of 2 different instances of same application, osascript returns same instance in exchange either pid - if first maps pid application name, , retrieves first application process name.

for example, start 2 different instances of vlc.app, playing 2 different video files, like:

open -na /applications/vlc.app ~/filea.m4v open -na /applications/vlc.app ~/fileb.m4v 

then obtain 2 separate application process ids with, example:

echo "$(ps -ceo pid=,comm= | awk '/vlc/ { print $1}')" 

we can use applescript or yosemite jxa javascript reference application object either pid.

it turns out, however, whichever process id supply, returned reference same instance, running same video file, if osascript translates pid application name, , returns first process matches name.

yosemite javascript applications:

function run() {     var app = application.currentapplication();     app.includestandardadditions = true;      var lstvlc = app.doshellscript(             "echo \"$(ps -ceo pid=,comm= | awk '/vlc/ { print $1}')\""         ).split(/[\r\n]/).map(number).map(application);      return {         firstinstance: lstvlc[0].windows[0].name(),         secondinstance: lstvlc[1].windows[0].name()     }; } 

applescript:

on run {}     set strcmd "echo \"$(ps -ceo pid=,comm= | awk '/vlc/ { print $1}')\""     set lstnum paragraphs of (do shell script strcmd)     repeat 1 length of lstnum         set item of lstnum (item of lstnum) number     end repeat       tell application "system events"         set oproca first application process unix id = (item 1 of lstnum)         set oprocb first application process unix id = (item 2 of lstnum)     end tell      return [name of first window of oproca, name of first window of oprocb] end run 

any thoughts on route scripting each instance separately ?

for each instance, ask name of window same line specific process, :

set windownames {} set lstnum paragraphs of (do shell script "ps -ceo pid=,comm= | awk '/vlc/ { print $1}'") tell application "system events" repeat in lstnum     set end of windownames name of first window of (first application process unix id = i) end repeat return windownames 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -