Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AppleScript to find a running instance of irssi in my iTerm windows, and launch one if not. For use with an application launcher such as Alfred.
tell application "iTerm"
activate
-- Change this if you want to find a different process
set myprocess to "irssi"
set procrunning to false
-- Count the number of terminal windows open
set mytermcount to count of terminal
-- If there are no terminal windows open,
-- just launch irssi immediately
if mytermcount is 0 then
set newterm to (make new terminal)
tell newterm
launch session "Default"
tell current session
write text myprocess
end tell
set procrunning to true
end tell
-- What to do if terminal windows are open
else
-- Open each terminal window in turn
repeat with i from 1 to mytermcount by 1
set myterm to (terminal i)
tell myterm
-- Count the number of sessions/tabs
-- open in this terminal window
set mytabcount to count of session
-- Open each session in turn
repeat with j from 1 to mytabcount by 1
set mysession to (session j)
-- If we find irssi, go to it
tell mysession
if name of mysession is myprocess then
select myterm
select mysession
set procrunning to true
end if
end tell
end repeat
end tell
end repeat
end if
-- If terminal windows are open but irssi isn't running
if procrunning is false then
set myterm to (make new terminal)
tell myterm
launch session "Default"
tell current session
write text myprocess
end tell
set procrunning to true
end tell
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment