通过终端/bashscript 将参数传递给 applescript 时出现问题

发布于 2024-11-14 13:03:56 字数 1928 浏览 3 评论 0原文

我试图通过 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 脚本调用基于 另一个关于在循环中执行 shell 脚本的问题,效果很好。

到目前为止,我发现它无法识别以下行中的 pid

 set VLC_VGA to application processes whose unix id is pid

。即使 pid 已正确传递并且 echo (ln2) 显示正确的 pid,VLC_VGA 上的 echo (ln3) 之后也不会返回任何内容。

我在这里做错了什么?

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:

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

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:

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

I call the script via

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

This does not work anymore - the pid is not recognized. The do shell script calls are based on another question on do shell scripts in loops, which work fine.

So far what I have found out is that it can't recognize the pid on the following line

 set VLC_VGA to application processes whose unix id is pid

The echo (ln3) on VLC_VGA afterwards returns nothing even though the pid is passed correctly and the echo (ln2) shows the correct pid.

What am I doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙味迷妹 2024-11-21 13:03:56

已解决的问题:pid 需要作为整数传递。

如:

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

Issue solved: the pid needs to be passed as an integer.

As in:

set VLC_VGA to application processes whose unix id is pid as integer
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文