« 10:[LOCAL]PUSH | トップページ | [Terminal] python3 pip のアップデートとパッケージのアップデート »

[Terminal]コマンド実行後指定秒数で終了し閉じる


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

##最大待ち時間 秒
set numMaxRepeatTime to 5 as integer

###実行するコマンド
tell application "Terminal"
activate
do script "/sbin/ping www.yahoo.co.jp"
end tell
delay 2


###くりかえし
repeat numMaxRepeatTime times
  tell application "Terminal"
    ##Windowの数を数えて
    set numCntWindow to (count of every window) as integer
    if numCntWindow = 1 then
log "Windowがありません"
      exit repeat
    end if
    tell front window
      ##WindowIDを取得
      set numWindowID to id
      tell front tab
        ##コマンド実行中か?
        set boolBusy to busy as boolean
      end tell
    end tell
  end tell
  ##終了しているなら
  if boolBusy is false then
log "処理していないので閉じる"
    tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
    end tell
    exit repeat
    ##コマンド実行中なら
  else
log "busyなので1秒まつ"
delay 1
  end if
end repeat
###くりかえしを抜けたあとで
tell application "Terminal"
  tell front window
    set numWindowID to id
    tell front tab
      ##今一度実行中か?確認して
      set boolBusy to busy as boolean
    end tell
  end tell
end tell
###実行中ならCTL+Cを送って中断させて
if boolBusy is true then
  tell application "System Events"
    tell application "Terminal" to activate
keystroke "c" using {control down}
  end tell
  ##Windowを閉じる
  tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
  end tell
  
end if



return


|

« 10:[LOCAL]PUSH | トップページ | [Terminal] python3 pip のアップデートとパッケージのアップデート »

Terminal」カテゴリの記事