2013-06-20 53 views
1

我有一個腳本有兩個蘋果腳本,它們打開一個新標籤並執行命令。我希望第二個蘋果腳本等到第一個蘋果腳本的命令行動作完成。我寧願不需要長時間睡眠,在它繼續之前。讓腳本等到最後一個腳本完成

有沒有辦法可以做到這一點?

以下是我有:

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' 

回答

3

您可以檢查窗口或標籤的忙屬性:

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 
+0

這不會對'ssh'連接工作 – Mausy5043