ターミナル ウィンドウを全部閉じる
##起動
tell application "Terminal" to launch
##起動確認 最大10秒
repeat 10 times
tell application "Terminal"
activate
set boolFrontMost to frontmost as boolean
end tell
if boolFrontMost is false then
delay 1
else
exit repeat
end if
end repeat
###ウィンドウがあるか?
tell application "Terminal"
set numCntWindow to (count of every window) as integer
end tell
###windowがある場合は先に閉じる 強制的に全部閉じる
###処理中のプロセスにもCTRL+Cを送って中止させます
if numCntWindow ≠ 0 then
repeat numCntWindow times
####CTRL+Cを送って
tell application "System Events"
tell process "Terminal"
tell front window
keystroke "c" using {control down}
keystroke "c" using {control down}
end tell
end tell
end tell
####exitしてからCLOSEする
tell application "Terminal"
##root対策で2回
do script "exit" in front window
do script "exit" in front window
tell front window
close saving no
end tell
end tell
end repeat
end if
###新しいウィンドウを作る
tell application "Terminal"
set refWindow1 to do script "\n\n"
log refWindow1
end tell
###新しいウィンドウを作る
tell application "Terminal"
set refWindow2 to do script "\n\n"
log refWindow2
end tell
###WINDOWを指定して実行する
tell application "Terminal"
do script "date" in refWindow1
end tell
tell application "Terminal"
do script "time" in refWindow2
end tell
| 固定リンク
« ターミナルにCTRL+C コントロール+Cを送る | トップページ | [NSString]空のテキストファイルを作る writeToFile:atomically:encoding:error: »
「Terminal」カテゴリの記事
- [Terminal]新規Windowでコマンドを実行するまでの一連の流れ(2025.01.13)
- ターミナル終了(複数Window 複数tab時)(2024.12.30)
- ターミナル終了(単Window時)(2024.12.30)
- ターミナル 実行中のプロセスの終了とウィンドウを閉じる(2024.11.24)
- [Terminal]スクリプト実行後終了したらTerminalも終了する(2024.11.14)