Я пытаюсь управлять несколькими экземплярами VLC через bashscript и applecript - я получаю к ним доступ через их 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 основаны на другой вопрос о сценариях do shell в циклах , которые работают нормально.
Пока что я обнаружил, что он не может распознать pid в следующей строке
set VLC_VGA to application processes whose unix id is pid
Эхо (ln3) на VLC_VGA впоследствии ничего не возвращает, даже если pid пройден правильно, и echo (ln2) показывает правильный pid.
Что я здесь не так делаю?