【问题标题】:Have a script wait until the last script is complete让脚本等到最后一个脚本完成
【发布时间】:2013-06-21 07:22:15
【问题描述】:

我有一个脚本,其中有两个苹果脚本可以打开一个新标签并执行一个命令。我希望第二个苹果脚本等到第一个苹果脚本的命令行操作完成。在它继续之前,我宁愿不必只睡 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'

【问题讨论】:

    标签: shell applescript


    【解决方案1】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 2020-05-18
      • 1970-01-01
      • 2023-03-09
      • 2015-07-11
      • 1970-01-01
      • 2013-06-30
      相关资源
      最近更新 更多