[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 framework "AppKIt"
use framework "UniformTypeIdentifiers"
use scripting additions
set strBundleID to "com.apple.Terminal"
###起動はランチを使うと新規ウィンドウが出来ない
tell application "Terminal" to launch
###ウィンドウの数を数えて
tell application "Terminal"
activate
set numCntWindow to (count of every window) as integer
end tell
###ウィンドウが無いなら終了する
if numCntWindow = 0 then
tell application "Terminal" to quit
delay 2
tell application "Terminal" to launch
end if
####新規ウィンドウを開く(SystemEvent方式)
tell application "Terminal"
activate
tell application "System Events"
tell process "Terminal"
set frontmost to true
key down {command}
keystroke "n"
key up {command}
end tell
end tell
end tell
###システムイベントの場合ウィンドウが出来るのを待つ
repeat 5 times
tell application "Terminal"
set numCntWindow to (count of every window) as integer
end tell
if numCntWindow = 0 then
delay 0.5
else
exit repeat
end if
end repeat
tell application "Terminal"
tell front window
set numWindowID to id as integer
end tell
tell window id numWindowID
set position to {0, 25}
end tell
end tell
###新規ウィンドウを開く(do script方式)
tell application "Terminal"
launch
activate
set objTabWindows to do script "\n"
tell objTabWindows
activate
end tell
end tell
####新規ウィンドウを開く
tell application "Terminal"
activate
tell application "System Events"
tell process "Terminal"
set frontmost to true
click menu item "タブを新しいウインドウに移動" of menu 1 of menu bar item "ウインドウ" of menu bar 1
end tell
end tell
tell front window
set numWindowID to id as integer
end tell
tell window id numWindowID
set position to {0, 340}
end tell
end tell
| 固定リンク
「Terminal」カテゴリの記事
- [Terminal]新規Windowでコマンドを実行するまでの一連の流れ(2025.01.13)
- ターミナル終了(複数Window 複数tab時)(2024.12.30)
- ターミナル終了(単Window時)(2024.12.30)
- ターミナル 実行中のプロセスの終了とウィンドウを閉じる(2024.11.24)
- [Terminal]スクリプト実行後終了したらTerminalも終了する(2024.11.14)