Last active
February 23, 2026 21:22
-
-
Save danielsgriffin/dadd47e21b98bbebc89b13ff307af5e1 to your computer and use it in GitHub Desktop.
ghostty-tab: Open a new Ghostty tab and run a command (macOS AppleScript workaround)
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
| #!/bin/bash | |
| # ghostty-tab: Open a new Ghostty tab and run a command in it | |
| # | |
| # Ghostty doesn't yet have a CLI flag or IPC for opening tabs in an | |
| # existing instance (pending their Scripting API). This uses AppleScript | |
| # keystrokes as a workaround. macOS only. | |
| # | |
| # Requires: System Settings > Privacy & Security > Accessibility | |
| # permission for osascript (or the parent process). | |
| # | |
| # Usage: ghostty-tab "cd ~/projects/foo && claude 'prompt here'" | |
| # | |
| # Works well with Claude Code dispatch workflows — open a new tab | |
| # with a pre-loaded prompt: | |
| # ghostty-tab "cd ~/projects/my-worktree && claude 'Read .claude/dispatch-context.md'" | |
| if [ -z "$1" ]; then | |
| echo "Usage: ghostty-tab <command>" | |
| exit 1 | |
| fi | |
| osascript - "$1" <<'APPLESCRIPT' | |
| on run argv | |
| set cmd to item 1 of argv | |
| tell application "Ghostty" | |
| activate | |
| tell application "System Events" | |
| keystroke "t" using command down | |
| delay 0.5 | |
| keystroke cmd | |
| key code 36 | |
| end tell | |
| end tell | |
| end run | |
| APPLESCRIPT |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This sends synthetic keystrokes via System Events — understand what that means before granting Accessibility access.