Wednesday, November 19, 2008

Open in Terminal (4 Ways)

One of the cool little helpers I talk about in The Productive Programmer is "Command Prompt Here" or "Bash Here": little context menu items for Windows that allow you to select a folder in Explorer, right click, and open a command prompt (or bash shell, if you are using Cygwin) at that location. Someone recently asked me if you can do this on the Mac, and it turns out you can, in a surprisingly large number of ways.

The first way leverages Automator to create a little script that makes an Automator plug-in for Finder. This trick appears here. The cool thing about this tip is the stuff it teaches about building Finder extension via Automator, which is a pretty cool subject unto itself. However, the bad thing about the final solution proffered by this tip is the location where the context menu appears: 2 levels down in the right-click menu, under Automator. Too much clicking.

Not being satisfied with the above, I found an alternative, which creates a toolbar icon at the top of Finder that opens the current selected folder (or the folder of the currently selected file) when you click on it. This trick appears here. The only downside of this version is the number of windows it spawns: one per request, instead of opening new tabs (it was created before Terminal supported tabs in Leopard). So, not to be outdone, the author describes the steps to upgrade it to tabbed terminal in Leopard here. One gotcha exists in his instructions: he says to replace the original script with the one found on this page, but I assumed you could do that with a text editor. It turns out that you need to use the script editor that launches when you double-click the main.scpt file. Otherwise, it works like a charm.

The reason I haven't pursued this before on the Mac? I generally use PathFinder, which includes not only a context menu for "Open in Terminal", it also has an embedded Terminal, which opens in the current folder. Highly recommended, but it you don't want to spend the money, you can get the same effect by harvesting the links in this entry.