Skip to content

Instantly share code, notes, and snippets.

@danielsgriffin
Last active February 23, 2026 21:22
Show Gist options
  • Select an option

  • Save danielsgriffin/dadd47e21b98bbebc89b13ff307af5e1 to your computer and use it in GitHub Desktop.

Select an option

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)
#!/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
@danielsgriffin

Copy link
Copy Markdown
Author

This sends synthetic keystrokes via System Events — understand what that means before granting Accessibility access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment