1

I'm trying to control multiple VLC instances via bashscript and applescript - i access them via their pid. I got this working in a small manual test, which works fine:

tell application "System Events"
set VLC_VGA to application processes whose unix id is 598
repeat with proc in VLC_VGA
    set the frontmost of proc to true
    keystroke "p" using {command down}
end repeat
end tell

I now want to dynamically insert the pid (598 or whatever it may be). This is what I have so far - but won't work:

property accumulator : ""

on run argv
set vlcPID to item 1 of argv
set accumulator to do shell script "echo 'echo test returns'" without altering line endings
startPlayingVLC(vlcPID)
set ln to do shell script "echo 'started VLC instance: " & vlcPID & "'" without altering line endings
set accumulator to accumulator & ln
return accumulator
end run

on startPlayingVLC(pid)
tell application "System Events"
    set ln2 to do shell script "echo 'starting VLC instance: " & pid & "'" without altering line endings
    set accumulator to accumulator & ln2
    set VLC_VGA to application processes whose unix id is pid
    set ln3 to do shell script "echo 'VLC_VGA process: " & VLC_VGA & "'" without altering line endings
    set accumulator to accumulator & ln3
    repeat with proc in VLC_VGA
        set the frontmost of proc to true
        keystroke "p" using {command down}
    end repeat
end tell
end startPlayingVLC

I call the script via

osascript /Users/devuser/Development/AppleScript/playVLCAppViaPID.scpt 598

This does not work anymore - the pid is not recognized. The do shell script calls are based on another question on do shell scripts in loops, which work fine.

So far what I have found out is that it can't recognize the pid on the following line

 set VLC_VGA to application processes whose unix id is pid

The echo (ln3) on VLC_VGA afterwards returns nothing even though the pid is passed correctly and the echo (ln2) shows the correct pid.

What am I doing wrong here?

Community
  • 1
  • 1
Mike F
  • 1,224
  • 4
  • 26
  • 44
  • SOLVED: pid needs to be passed as integer: "pid as integer" as in `set VLC_VGA to application processes whose unix id is pid as integer` – Mike F Jun 09 '11 at 13:27
  • If you want to build some credibility here (by having a higher repuation score), post this as an answer, and then accept your own answer. 15 points! Thanks for sharing the answer and Good luck. – shellter Jun 09 '11 at 23:24
  • To get your 15 points, you have to check your answer as accepted. See the FAQ at http://tinyurl.com/2vycnvr Good luck! – shellter Jun 10 '11 at 23:12
  • @shellter: thanks for the info... should be checked as answered now, just didn't have the time yet. Thx again for the input! – Mike F Jun 14 '11 at 10:06
  • 1
    Sorry about that, you don't get the points. I'm relatively new here, and I thought I had seen cases where people did get points, I guess it was from something else. Sorry, but keep posting. Good luck. – shellter Jun 14 '11 at 16:15

1 Answers1

0

Issue solved: the pid needs to be passed as an integer.

As in:

set VLC_VGA to application processes whose unix id is pid as integer
Mike F
  • 1,224
  • 4
  • 26
  • 44