Today's tip is just a re-implementation of a really old Mac OS X Hints AppleScript that lets you open a Terminal window with the working directory set to (i.e. cd'd into) the selected Finder folder.
This makes it really easy to jump into Terminal to do something from Finder, without having to do any mousing and minimal typing. What's new is that I've used Keyboard Maestro to turn the AppleScript into a macro that runs only in Finder, where it's available via hot key or menu bar trigger.
Here's the complete macro; download it now to look at and/or use as you wish. [Note: If you use iTerm2 instead of Terminal, you'll want to download this version instead. My good friend James, who runs Out of Control, did so. He tells me it works great.]
The name of the macro may look a bit odd—the 03) controls the sort order in the Keyboard Maestro menu bar item, and does not display when the menu is activated:
Keyboard Maestro also helpfully displays the assigned keyboard shortcut in the menu bar item, in case I've forgotten it.
I like this macro because it's incredibly easy to use; it doesn't matter if you have a folder or file selected. Just invoke the macro, and Terminal opens to either the selected folder, or to the folder containing the selected file:
If you'd just like the AppleScript bit to use elsewhere, here it is:
tell application "Finder"
set theWin to (quoted form of POSIX path of (target of window 1 as alias))
tell application "Terminal"
tell window 1
do script "cd " & theWin
That's really all there is to it—just a simple little macro that makes it much easier to jump into Terminal when I realize I need it set to the folder I'm currently browsing in Finder.