Created
March 29, 2018 16:23
-
-
Save ohayon/d22b4ee13830ef223d432ba8615c5948 to your computer and use it in GitHub Desktop.
hammerspoon config
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
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