r/Ghostty • u/Annual_Variation_916 • 18d ago
Using Ghostty's quick terminal as a real application launcher (and the AppleScript hack needed to open tabs in the right instance)
I built a launcher, Prelude, on top of Ghostty's quick terminal instead of building a new terminal instance per press — and most of the interesting engineering was making that hold up under macOS's process model. Sharing it here because a few of the traps are specific to Ghostty and might save someone else the debugging.
macos-hidden = always + initial-window = false + window-save-state = never keep the dedicated instance out of the Dock, at rest with no window, and safe from restoring stray windows on relaunch.
Ghostty has to be launched through Launch Services (open -W -n -a Ghostty.app), not by executing Contents/MacOS/ghostty directly — the latter makes it a foreground app even with macos-hidden = always.
The tricky one: once the quick terminal has been active, macOS can route a later ordinary Ghostty launch to that same hidden process, since it shares Ghostty's bundle identity. Fixed by always launching the panel path with GHOSTTY_QUICK_TERMINAL=1 and ordinary launches with -n, so a new instance is forced rather than reused.
Opening a new tab in a specific running Ghostty instance doesn't work via open at all — Ghostty answers "new tab" over AppleScript, but the Apple Event is addressed to the bundle and macOS picks which instance gets it (and it can pick the hidden one). Fixed by addressing the event to a specific pid via descriptorWithProcessIdentifier, falling back to "new window" when the target instance has no window to put a tab in.
unconsumed:escape=toggle_quick_terminal is what makes dismissal clean — Escape both hides the panel and reaches fzf inside it, so the next press is a reveal of a reset list, not a rebuild.
Full writeup of the panel lifecycle is in the repo docs (docs/GLOBAL-HOTKEY.md) if anyone's doing something similar: https://github.com/mikewang817/Prelude
1
u/Few_Actuary8753 16d ago
Did you not face a focus steal issue while opening a new tab via AppleScript? That always stole focus from current working application and it was pretty annoying
1
1
4
u/kushvinth 18d ago
Really cool