-
Notifications
You must be signed in to change notification settings - Fork 76
/
is-iterm2-active.applescript
executable file
·32 lines (26 loc) · 1.09 KB
/
is-iterm2-active.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/osascript
on run ttyName
try
set ttyName to first item of ttyName
on error
set ttyName to ""
end
if ttyName is equal to "" then error "Usage: is-iterm2-active.applescript TTY"
tell application id "com.googlecode.iterm2"
tell current window
set isHotkeyWindow to is hotkey window
if isHotkeyWindow and visible is not true then error "iTerm is not the frontmost application"
end tell
end tell
if isHotkeyWindow is not true then
tell application "System Events"
tell item 1 of (application processes whose bundle identifier is "com.googlecode.iterm2")
if frontmost is not true then error "iTerm is not the frontmost application"
end tell
end tell
end if
tell application id "com.googlecode.iterm2"
set currentTty to tty of (current session of current tab of current window) as text
if currentTty is not equal to ttyName then error "Current tab TTY '" & currentTty & "' does not match expected '" & ttyName & "'"
end tell
end run