2011-06-09 1 views
1

J'essaie de contrôler plusieurs instances de VLC via bashscript et applescript - j'y accède via leur pid. Je suis arrivé ce travail dans un petit test manuel, qui fonctionne très bien:Problème de passage du paramètre à applescript via le terminal/bashscript

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 

Je veux maintenant insérer dynamiquement le pid (598 ou quoi que ce soit). Voilà ce que j'ai à ce jour - mais ne travaillerai pas:

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 

J'appelle le script via

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

Cela ne fonctionne plus - le pid est pas reconnu. Les appels de script shell sont basés sur another question on do shell scripts in loops, qui fonctionnent correctement.

Jusqu'à présent, ce que j'ai découvert est qu'il ne peut pas reconnaître le pid sur la ligne suivante

set VLC_VGA to application processes whose unix id is pid 

L'écho (LN3) sur VLC_VGA revient après rien, même si le pid est passé correctement et echo (ln2) montre le bon pid.

Qu'est-ce que je fais mal ici?

+0

RESOUDRE: besoins pid à passer en entier: "pid entier" comme dans 'set VLC_VGA aux processus d'application dont id unix est pid integer' –

+0

Si vous voulez construire une certaine crédibilité ici (en ayant un score de rééducation plus élevé), postez cela comme une réponse, puis acceptez votre propre réponse. 15 points! Merci de partager la réponse et bonne chance. – shellter

+0

Pour obtenir vos 15 points, vous devez vérifier votre réponse comme acceptée. Voir la FAQ à http://tinyurl.com/2vycnvr Bonne chance! – shellter

Répondre

0

Problème résolu: le pid doit être passé en entier.

Comme dans:

set VLC_VGA to application processes whose unix id is pid as integer 
Questions connexes