Opening folders in TextMate via Finder context menus
OSX’s Finder allows you to send files to applications through the “Open With” context menu option. However, this is not available when the context menu is opened over folders.
Some applications, however, do interesting things when you open folders in them. TextMate, for example, opens the folder in project view, so you can use its drawer to browse documents in the folder and its subfolders.
There are various guides on the web that explain how to setup folder access to TextMate from Finder context menus, but I noticed that they contain some superfluous steps and don’t work with pathnames that have spaces in them. Here’s my slight variant:
- Make sure that the
matecommand is in your execution path. (cf. the entry in the official blog on how to do this).
- Launch Applications > Automator.
- Select File > New and choose the Service template. This will create a new workflow, which is a GUI script that will perform some task.
- Change the Service receives selected drop-down option from text to files or folders.
- Add a Run Shell Script action to the workflow. You can do this by searching for the phrase “run shell script”, and then double-clicking on the resulting option.
- Change the Pass input: drop-down option from as arguments to to stdin. Each file or folder selected in Finder will be passed to our workflow via standard input, separate by newlines.
- Paste the following shell command into the text area:
sed 's/ /\ /g' | xargs mate
- Save the workflow, using the name of the option you want to appear in your context menu. I used “Open in TextMate”.
- This workflow will get saved into
~/Library/Services. It will appear automatically in your context menu.
This should allow you to open any number of files or folders in TextMate via Finder, including pathnames that contain spaces. It may run into issues if your pathnames contain quote characters, but let’s hope those are few and far between.