Skip to content

Instantly share code, notes, and snippets.

@alessaba
Last active July 30, 2025 20:53
Show Gist options
  • Save alessaba/382b506ae6d7d239e63b62860337d3c6 to your computer and use it in GitHub Desktop.
Save alessaba/382b506ae6d7d239e63b62860337d3c6 to your computer and use it in GitHub Desktop.
This script opens OpenCode in the selected Finder folder using Ghostty
on run {input, parameters}
try
-- Determine the folder path
if (count of input) > 0 then
set selectedItem to item 1 of input
set itemAlias to selectedItem as alias
set itemInfo to info for itemAlias
if folder of itemInfo is true then
set folderPath to POSIX path of itemAlias
else
set folderPath to POSIX path of (container of itemAlias)
end if
else
-- If nothing is selected, use the current Finder window's target
tell application "Finder"
try
set currentWindow to target of front window
set folderPath to POSIX path of (currentWindow as alias)
on error
set folderPath to POSIX path of (path to desktop)
end try
end tell
end if
-- Launch Ghostty and type commands to navigate and start OpenCode
tell application "Ghostty"
activate
delay 0.5
end tell
tell application "System Events"
keystroke "c" using {control down}
delay 0.1
keystroke "opencode " & quoted form of folderPath
delay 0.1
key code 36 -- Enter
end tell
on error errorMessage
display dialog "Error starting OpenCode: " & errorMessage buttons {"OK"} default button "OK" with icon caution
end try
return input
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment