【发布时间】:2011-06-10 16:19:05
【问题描述】:
我正在尝试通过 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
VLC_VGA 上的 echo (ln3) 之后即使 pid 正确传递并且 echo (ln2) 显示正确的 pid,也不返回任何内容。
我在这里做错了什么?
【问题讨论】:
-
已解决:pid 需要作为整数传递:"pid as integer" 如
set VLC_VGA to application processes whose unix id is pid as integer -
如果您想在这里建立一些可信度(通过获得更高的声誉分数),请将其发布为答案,然后接受您自己的答案。 15分!感谢您分享答案,祝您好运。
-
要获得 15 分,您必须检查您的答案是否被接受。请参阅tinyurl.com/2vycnvr 的常见问题解答,祝你好运!
-
@shellter:感谢您提供的信息...现在应该按照已回答的方式进行检查,只是还没有时间。再次感谢输入!
-
对不起,你没有得到分数。我在这里相对较新,我以为我见过人们确实获得积分的案例,我猜是其他原因。对不起,但请继续发帖。祝你好运。
标签: shell parameters applescript vlc pid