macOS: AppleScript interface for Ghostty Automations #10201
Unanswered
kkilchrist
asked this question in
Feature Requests, Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR:
Extensive AppleScript support for Ghostty wrapping all App Intents.
AppleScript models "terminal" objects properties index (1-indexed), uuid, title, working directory, current window contents. This implementation wraps existing Ghostty APIs rather than creating parallel code paths. (c.f. @j-c-m 's earlier discussion/work here)
code is here https://github.com/kkilchrist/ghostty-applescript
I can share a notarized binary (signed with my account) if anyone is unable to build but wants to test, but better to build yourself if possible.
Problem:
There are several discussions around how Ghostty's behavior on macOS
open -n "Ghostty"leave something to be desired. In my use case, I built a menu bar app to invoke Claude code with a particular directory + model + prompt (e.g., paste bug to create categorized issue in some repo). My preferred interface is Ghostty.ghosttycli commands on Mac (unlike Linux)open -a "Ghostty" somecommanddoes not workopen -na Ghostty.app --args -e /bin/bash -c "cd '~/some-directory' && somecommand"but this opened new instances of Ghostty.app for each new session.c.f. 1, 2
As a workaround, many users report using system events scripting and key bindings (e.g., "focus on Ghostty" then "click File -> New Window" then paste my command). But this is hackish and gives limited true automation potential, especially to do anything other than "launch and forget"
Ghostty already supports the App Intent framework, but as far as I can tell, this is not accessible from another application or script, without the user creating a Shortcut that can be invoked.
I have another app I am working on which implements AppleScript (in my case, for Claude Code to navigate and control my markdown viewer which operates from within the AppStore sandbox).
So, Claude Code and I wrapped the existing Ghostty App Intents with AppleScript, with the aim of implementing AppleScript (bindings/interfaces) for all exposed App Intents, and added a couple new aspects for ergonomics.
Examples:
osascript -e 'tell application "Ghostty" to new terminal'osascript -e 'tell application "Ghostty" to new terminal command "htop"'osascript -e 'tell application "Ghostty" to new terminal directory "~/projects"'osascript -e 'tell application "Ghostty" to new terminal command "htop" directory "/tmp"'osascript -e 'tell application "Ghostty" to new terminal location tab'osascript -e 'tell application "Ghostty" to new terminal location tab command "htop"'osascript -e 'tell application "Ghostty" to open quick terminal'osascript -e 'tell application "Ghostty" to send text "feedback for claude" to terminal 1'osascript -e 'tell application "Ghostty" to get contents of terminal 1'osascript -e 'tell application "Ghostty" to split direction right in terminal 1'After I had substantially completed this work, I found @j-c-m 's earlier discussion here and PR.
That implementation has not seen activity since October, and implemented a relatively limited number of controls. Apologies that I did not build on top of it.
waitafter commandHappy to make any changes as the community would like. Can also add features like zoom etc, although these are already accessible via applescript -> keybinding handlers
Disclosures:
Beta Was this translation helpful? Give feedback.
All reactions