ターミナル 実行中のプロセスの終了とウィンドウを閉じる
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | use AppleScript version "2.4" |
003 | use scripting additions |
004 | |
005 | set numMaxCnt to 10 as integer |
006 | set numCntSec to 0 as integer |
007 | |
008 | |
009 | tell application id "com.apple.Terminal" to quit |
010 | delay 1 |
011 | tell application "Terminal" to launch |
012 | tell application "Terminal" |
013 | do script "\n" |
014 | delay 1 |
015 | do script "tail -f /var/log/system.log" in front tab of front window |
016 | end tell |
017 | |
018 | |
019 | repeat numMaxCnt times |
020 | tell application "Terminal" |
021 | set boolRunning to not (running) |
022 | tell front window |
023 | tell front tab |
024 | set boolbusy to busy as boolean |
025 | end tell |
026 | end tell |
027 | end tell |
028 | set numCntSec to numCntSec + 1 as integer |
029 | if numCntSec ≥ numMaxCnt then |
030 | exit repeat |
031 | else |
032 | delay 1 |
033 | end if |
034 | end repeat |
035 | ##コントロールCを送って中断させる |
036 | if boolbusy is true then |
037 | tell application "Terminal" |
038 | activate |
039 | tell front window |
040 | activate |
041 | tell front tab |
042 | activate |
043 | tell application "System Events" |
044 | tell process "Terminal" |
045 | key down {control} |
046 | keystroke "c" |
047 | key up {control} |
048 | end tell |
049 | end tell |
050 | end tell |
051 | end tell |
052 | end tell |
053 | end if |
054 | |
055 | tell application "Terminal" |
056 | activate |
057 | do script "exit" in front tab of front window |
058 | end tell |
059 | delay 1 |
060 | tell application "Terminal" |
061 | activate |
062 | tell front window |
063 | close |
064 | end tell |
065 | end tell |
066 | |
067 | |
068 | tell application "Terminal" to quit |
AppleScriptで生成しました |
| 固定リンク
「Terminal」カテゴリの記事
- [Terminal]新規Windowでコマンドを実行するまでの一連の流れ(2025.01.13)
- ターミナル終了(複数Window 複数tab時)(2024.12.30)
- ターミナル終了(単Window時)(2024.12.30)
- ターミナル 実行中のプロセスの終了とウィンドウを閉じる(2024.11.24)
- [Terminal]スクリプト実行後終了したらTerminalも終了する(2024.11.14)