Skip to content

Instantly share code, notes, and snippets.

@cmsj
Created March 16, 2017 17:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmsj/6fb4e4a8d7edd6c9d89a2d529e52ce5f to your computer and use it in GitHub Desktop.
Save cmsj/6fb4e4a8d7edd6c9d89a2d529e52ce5f to your computer and use it in GitHub Desktop.
lastApp = nil
function launchFocusOrSwitchBack(appName)
-- This function will launch appName if it's not running, focus
-- it if it is running, or if it's already focused, switch back
-- to whatever the last focused App was
-- (The Pro version of this would use hs.windowfilter to track
-- window focus events, but for now we'll just assume that this
-- is the only way apps will be switched)
local currentApp = hs.application.frontmostApplication()
if lastApp and currentApp and (currentApp:name() == appName) then
lastApp:activate()
else
hs.application.launchOrFocus(appName)
end
lastApp = currentApp
end
hs.hotkey.bind({"cmd", "alt"}, "i", function() launchFocusOrSwitchBack("iTerm") end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment