2011-06-09 86 views
1

我想通過bashscript和applescript控制多個VLC實例 - 我通過他們的pid訪問它們。我在一家小手工測試,工作正常,得到了這個工作:通過終端/ bashscript傳遞參數到applescript的問題

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 

我現在要動態插入PID(598或任何可能)。這是我迄今爲止 - 但將無法正常工作:

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 

我通過

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

調用腳本這不工作了 - 的PID不被認可。 do shell腳本調用基於another question on do shell scripts in loops,這很好。

到目前爲止,我所發現的是,它無法識別以下行的PID

set VLC_VGA to application processes whose unix id is pid 

上VLC_VGA回聲(LN3)之後沒有返回,即使PID正確過去了, echo(ln2)顯示正確的pid。

我在這裏做錯了什麼?

+0

解決:在'設置VLC_VGA「PID爲整」,以應用程序進程,其UNIX id爲PID爲integer' – 2011-06-09 13:27:38

+0

如果你想建立:PID需要爲整傳遞這裏有一些可信度(通過獲得更高的再評分),將其作爲答案發布,然後接受自己的答案。 15分!感謝分享答案和祝你好運。 – shellter 2011-06-09 23:24:57

+0

要得到15分,你必須檢查你的答案爲接受。請參閱http://tinyurl.com/2vycnvr上的常見問題祝你好運! – shellter 2011-06-10 23:12:53

回答

0

問題解決:pid需要作爲整數傳遞。

如:

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