6

我有一个脚本,它有两个苹果脚本,可以打开一个新选项卡并执行一个命令。我希望第二个苹果脚本等到第一个苹果脚本的命令行操作完成。在它继续之前,我宁愿不必只睡 x 久。

有没有办法我可以做到这一点?

这是我所拥有的:

 osascript -e 'tell application "Terminal" to activate' \
 -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \
 -e 'tell application "Terminal" to do script "cd '$current_dir'" in selected tab of the front window' \
 -e 'tell application "Terminal" to do script "./my_script arg1" in selected tab of the front window'

 ------ Wait until this process is finished -------

 osascript -e 'tell application "Terminal" to activate' \
 -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \
 -e 'tell application "Terminal" to do script "cd '$current_dir'" in selected tab of the front window' \
 -e 'tell application "Terminal" to do script "./my_script different_arg1" in selected tab of the front window'
4

1 回答 1

6

您可以检查窗口或选项卡的忙属性:

tell application "Terminal"
    set w to do script "sleep 1"
    repeat
        delay 0.1
        if not busy of w then exit repeat
    end repeat
end tell
osascript -e 'on run {a}
    tell application "Terminal"
        activate
        tell application "System Events" to keystroke "t" using command down
        do script "cd " & quoted form of a & "; sleep 1" in window 1
        repeat
            delay 0.1
            if not busy of window 1 then exit repeat
        end repeat
        tell application "System Events" to keystroke "t" using command down
        do script "cd " & quoted form of a & "; sleep 1" in window 1
    end tell
end run' /tmp
于 2013-06-20T23:22:15.277 回答