bash用 コマンドが終了したらターミナルのウィンドウを閉じる
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | |
003 | |
004 | #実行するコマンド |
005 | #XProtectのマルウェアスキャン実行 |
006 | set strCommandText to ("/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/MacOS/XProtect") as text |
007 | |
008 | #ターミナル |
009 | tell application "Terminal" |
010 | #起動 |
011 | launch |
012 | #前面に |
013 | activate |
014 | #新規Windowでシェルを実行 |
015 | set objWindowID to (do script "/bin/bash\n\n") |
016 | delay 1 |
017 | #WidnowのIDを取得 |
018 | do script strCommandText in objWindowID |
019 | #確実にウィンドウが出来るのをまつ |
020 | delay 1 |
021 | tell front window |
022 | tell front tab |
023 | #プロセスが終わるまで繰り返し |
024 | repeat |
025 | #フロントタブで実行中のプロセス |
026 | set listProcesses to processes as list |
027 | #処理終了のデフォルト値 NO |
028 | set boolProcessesDone to false as boolean |
029 | #プロセスリストの数だけ繰り返し |
030 | repeat with itemProcesses in listProcesses |
031 | #プロセス名がコマンドラインの内容に含んでいるか? |
032 | set boolContain to (strCommandText contains itemProcesses) as boolean |
033 | #含んでいる=まだ実行中 |
034 | if boolContain is true then |
035 | #終了判定 NO |
036 | set boolProcessesDone to false as boolean |
037 | else |
038 | #プロセス名が含まれない場合は 終了判定YES |
039 | set boolProcessesDone to true as boolean |
040 | end if |
041 | end repeat |
042 | #プロセス名を巡回チェックして |
043 | #終了判定が YESなら |
044 | if boolProcessesDone is true then |
045 | #リピートを抜けて終了処理に |
046 | exit repeat |
047 | else if boolProcessesDone is false then |
048 | #終了判定がNOなら 1秒まつ |
049 | delay 1 |
050 | end if |
051 | end repeat |
052 | #コマンドが終了したら |
053 | do script "\n\n" in objWindowID |
054 | #シェルをEXITして BASHを抜ける |
055 | do script "exit" in objWindowID |
056 | #コマンドが終了したら |
057 | do script "\n\n" in objWindowID |
058 | #シェルをEXITして ZSHを抜ける |
059 | do script "exit" in objWindowID |
060 | delay 1 |
061 | end tell |
062 | end tell |
063 | close front window saving no |
064 | set numCntWindow to (count of every window) as integer |
065 | |
066 | repeat with itemWindowID from 1 to (numCntWindow) by 1 |
067 | close window itemWindowID saving no |
068 | end repeat |
069 | end tell |
070 | |
071 | |
072 | |
AppleScriptで生成しました |
| 固定リンク
「Terminal」カテゴリの記事
- [Terminal]新規Windowでコマンドを実行するまでの一連の流れ(2025.01.13)
- ターミナル終了(複数Window 複数tab時)(2024.12.30)
- ターミナル終了(単Window時)(2024.12.30)
- ターミナル 実行中のプロセスの終了とウィンドウを閉じる(2024.11.24)
- [Terminal]スクリプト実行後終了したらTerminalも終了する(2024.11.14)