Skip to content

Instantly share code, notes, and snippets.

@ohayon
Created March 29, 2018 16:23
Show Gist options
  • Save ohayon/d22b4ee13830ef223d432ba8615c5948 to your computer and use it in GitHub Desktop.
Save ohayon/d22b4ee13830ef223d432ba8615c5948 to your computer and use it in GitHub Desktop.
hammerspoon config
SHOULD_HIDE_ON_DEACTIVATE = true
function applicationWatcher(appName, eventType, appObject)
if (eventType == hs.application.watcher.deactivated) then
if (appName == "Terminal") then
if (SHOULD_HIDE_ON_DEACTIVATE == true) then
appObject:selectMenuItem({"Terminal", "Hide Terminal"})
end
end
end
end
appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start()
hs.hotkey.bind({"alt", "ctrl"}, "`", function()
appWatcher:stop()
SHOULD_HIDE_ON_DEACTIVATE = false
end)
hs.hotkey.bind({"cmd", "alt"}, "`", function()
appWatcher:start()
SHOULD_HIDE_ON_DEACTIVATE = true
end)
lastApp = hs.application()
hs.hotkey.bind({"alt"}, "`", function()
local front = hs.application.frontmostApplication()
if (front:name() == "Terminal") then
if (SHOULD_HIDE_ON_DEACTIVATE == true) then
front:hide()
else
hs.application.launchOrFocus(lastApp:name())
end
else
lastApp = front
hs.application.launchOrFocus("Terminal")
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment