Customizing the macOS Finder Toolbar with "Open Current Directory in Zed"

A friend of mine, Terry, asked a question on Twitter.
A long time ago, I added this button to open the current folder in vscode.
I obvs want it to open cursor now, but can't figure out how I put it up there!
Anyone know?
— https://x.com/saltcod/status/1890727453124968831
Well, I did not know how to do it, but because I always like to learn random things and, most of all, help people, I decided to figure it out. Here's how to do it in a few simple steps.
- Open the
Automator
app and create a new Application. - Add two steps:
Run AppleScript
andRun Shell Script
. - Fill the
AppleScript
step with the script below. It will grab the currently activeFinder
window and extract its current directory.
on run {input, parameters}
tell application "Finder"
set currentFolder to (target of front window) as alias
return POSIX path of currentFolder
end tell
end run
- Fill the
Shell Script
step with/usr/local/bin/zed "$1"
or any other editor of your choice. - Press
Cmd + S
to save the automation. It should now be accessible underApplications
on your system. - Go to your
Applications
, right-click the newly saved automation, and selectGet Info
. - Drag the application you used in your script and drop it on top of the small icon in the top left corner of the info window. This will give you a nicely styled icon.
- Open a new
Finder
window (you need two separate windows for this step), right-click on the toolbar, and selectCustomize Toolbar...
. - Focus on your original
Finder
window withApplications
, then drag and drop your automation next to the rest of your toolbar icons. - You're done! Now you can click your new shortcut in any
Finder
window, and it will open your editor with a workspace set to that very directory.