Created
December 8, 2012 15:56
-
-
Save hallski/4240823 to your computer and use it in GitHub Desktop.
Toggle terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set appName to "Terminal" -- openTerminalWindow requires Terminal | |
set newWindowScript to "tmux -2" -- set to "" to just run the shell | |
if not isRunning(appName) then tell application appName to activate | |
if numberOfWindows(appName) is 0 then | |
openTerminalWindow(appName, newWindowScript) | |
foregroundApp(appName) | |
else | |
if isCurrentApp(appName) then | |
hideApp(appName) | |
else | |
foregroundApp(appName) | |
end if | |
end if | |
-- Helper handlers | |
on isRunning(name) | |
tell application "System Events" to return exists process name | |
end isRunning | |
on isCurrentApp(name) | |
tell application "System Events" to return get frontmost of process name | |
end isCurrentApp | |
on numberOfWindows(name) | |
tell application "System Events" to tell process name to return count every window | |
end numberOfWindows | |
on openTerminalWindow(name, runScript) | |
tell application "Terminal" to set newTab to do script runScript | |
end openTerminalWindow | |
on hideApp(name) | |
tell application "System Events" to set visible of process name to false | |
end hideApp | |
on foregroundApp(name) | |
tell application name to activate | |
end foregroundApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment