问题传递参数通过终端/ bashscript的AppleScript [英] Problem passing parameter to applescript via terminal/bashscript

查看:426
本文介绍了问题传递参数通过终端/ bashscript的AppleScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图控制通过bashscript和AppleScript多个VLC实例 - 我通过他们的pid访问它们。我在一家小手工测试这方面的工作,这工作得很好:

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

我现在要动态插入PID(598或任何可能)。这是我迄今为止 - 但不会工作:

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

我通过

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

这不工作了 - 的PID不被认可。该做的shell脚本调用基于<一个href=\"http://stackoverflow.com/questions/274469/cant-do-shell-script-with-a-repeat-with-i-from-1-to-n-loop\"标题=粉粉做循环shell脚本问题>上做循环shell脚本的另一个问题,它做工精细。

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.

到目前为止,我所发现的是,它不能识别以下行PID

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

在VLC_VGA回声(LN3)之后返回,即使pid是正确传递什么和回声(LN2)显示正确的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.

我在做什么错在这里?

推荐答案

问题解决:pid的需要作为一个整数传递

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

如:

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

这篇关于问题传递参数通过终端/ bashscript的AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆