title: Problem passing parameter to applescript via terminal/bashscript
body: <p>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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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: " &amp; vlcPID &amp; "'" without altering line endings
  set accumulator to accumulator &amp; ln
  return accumulator
  end run
  
  on startPlayingVLC(pid)
  tell application "System Events"
      set ln2 to do shell script "echo 'starting VLC instance: " &amp; pid &amp; "'" without altering line endings
      set accumulator to accumulator &amp; ln2
      set VLC_VGA to application processes whose unix id is pid
      set ln3 to do shell script "echo 'VLC_VGA process: " &amp; VLC_VGA &amp; "'" without altering line endings
      set accumulator to accumulator &amp; 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
  </code></pre>
  
  <p>I call the script via</p>
  
  <pre><code>osascript /Users/devuser/Development/AppleScript/playVLCAppViaPID.scpt 598
  </code></pre>
  
  <p>This does not work anymore - the pid is not recognized. The do shell script calls are based on <a href="https://stackoverflow.com/questions/274469/cant-do-shell-script-with-a-repeat-with-i-from-1-to-n-loop" title="another question on do shell scripts in loops">another question on do shell scripts in loops</a>, which work fine.</p>
  
  <p>So far what I have found out is that it can't recognize the pid on the following line</p>
  
  <pre><code> set VLC_VGA to application processes whose unix id is pid
  </code></pre>
  
  <p>The echo (ln3) on VLC_VGA afterwards returns nothing even though the pid is passed correctly and the echo (ln2) shows the correct pid.</p>
  
  <p>What am I doing wrong here?</p>