« [CURL]ヘッダー付きダウンロード | トップページ | DS(デジタルセンド) »

ターミナル 実行中のプロセスの終了とウィンドウを閉じる


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002use AppleScript version "2.4"
003use scripting additions
004
005set numMaxCnt to 10 as integer
006set numCntSec to 0 as integer
007
008
009tell application id "com.apple.Terminal" to quit
010delay 1
011tell application "Terminal" to launch
012tell application "Terminal"
013  do script "\n"
014  delay 1
015  do script "tail -f /var/log/system.log" in front tab of front window
016end tell
017
018
019repeat 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
034end repeat
035##コントロールCを送って中断させる
036if 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
053end if
054
055tell application "Terminal"
056  activate
057  do script "exit" in front tab of front window
058end tell
059delay 1
060tell application "Terminal"
061  activate
062  tell front window
063    close
064  end tell
065end tell
066
067
068tell application "Terminal" to quit
AppleScriptで生成しました

|

« [CURL]ヘッダー付きダウンロード | トップページ | DS(デジタルセンド) »

Terminal」カテゴリの記事