我正在尝试通过bashscript和applescript控制多个VLC实例 - 我通过他们的pid访问它们。我在一个小的手动测试中工作,这很好用:
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
即使pid正确传递并且echo(ln2)显示正确的pid,VLC_VGA上的echo(ln3)之后也不会返回任何内容。
我在这里做错了什么?
答案 0 :(得分:0)
问题解决了:pid需要作为整数传递。
如:
set VLC_VGA to application processes whose unix id is pid as integer