Created
March 10, 2026 18:53
-
-
Save hohonuuli/14ca6f4d045899e2015e207e43821b61 to your computer and use it in GitHub Desktop.
Source code for a medium article
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
| (* | |
| Open Ghostty Here | |
| A toolbar script for macOS | |
| Written by Brian Schlining | |
| (Adapted from "Open Terminal Here" for iTerm) | |
| *) | |
| property debug : false | |
| -- when the toolbar script icon is clicked | |
| on run | |
| tell application "Finder" | |
| try | |
| set this_folder to (the target of the front window) as alias | |
| on error | |
| set this_folder to startup disk | |
| end try | |
| my process_item(this_folder) | |
| end tell | |
| end run | |
| -- This handler processes folders dropped onto the toolbar script icon | |
| on open these_items | |
| repeat with i from 1 to the count of these_items | |
| set this_item to item i of these_items | |
| my process_item(this_item) | |
| end repeat | |
| end open | |
| -- Does the actual work | |
| -- Handles edge cases like folders named "te'st"ö te%s`t" | |
| on process_item(this_item) | |
| set thePath to POSIX path of this_item | |
| tell application "Ghostty" | |
| activate | |
| set cfg to new surface configuration | |
| set initial working directory of cfg to thePath | |
| try | |
| set aWindow to front window | |
| set newTab to new tab in aWindow with configuration cfg | |
| set t to focused terminal of newTab | |
| on error | |
| set aWindow to new window with configuration cfg | |
| set t to focused terminal of selected tab of aWindow | |
| end try | |
| input text "clear" to t | |
| send key "enter" to t | |
| end tell | |
| end process_item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment