我有一个脚本,它有两个苹果脚本,可以打开一个新标签并执行命令。我希望第二个苹果脚本等到第一个苹果脚本的命令行动作完成。在继续之前,我宁愿不必长时间睡一觉。
我有办法做到这一点吗?
这就是我所拥有的:
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'
答案 0 :(得分: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