Created
February 19, 2026 12:52
-
-
Save dorelljames/1328e15bc758541c8ed97922b57c7953 to your computer and use it in GitHub Desktop.
Hammerspoon: Toggle Ghostty on current Space with Option+Escape
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
| -- Toggle Ghostty on current Space with Option+Escape | |
| -- Only activates if Ghostty has a window on the current Space. | |
| -- If no Ghostty window here, does nothing (no desktop switching). | |
| hs.hotkey.bind({"alt"}, "escape", function() | |
| local app = hs.application.find("ghostty") | |
| if not app then | |
| hs.application.launchOrFocus("Ghostty") | |
| return | |
| end | |
| if app:isFrontmost() then | |
| app:hide() | |
| return | |
| end | |
| -- Check if any Ghostty window is on the current space | |
| local currentSpace = hs.spaces.focusedSpace() | |
| local allWins = app:allWindows() | |
| for _, win in ipairs(allWins) do | |
| local winSpaces = hs.spaces.windowSpaces(win:id()) | |
| if winSpaces and hs.fnutils.contains(winSpaces, currentSpace) then | |
| app:activate() | |
| return | |
| end | |
| end | |
| -- No Ghostty window on this space — do nothing | |
| end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment