How To add “Open folder in Textmate” to Finder Context Menu

I wanted to add a menu item in Finder’s context menu that would open the selected folder in Textmate.
Textmate context menu item: Open selected folder in  Textmate

A google search suggested the method described by K. Adam Christensen on his blog: “Opening a directory in TextMate from Finder“. However, from the documentation, I learned that that method is now outdated. Snow Leopard users should use “Services” and not “workflow” for setting this up.

Here is what I did:

Open Automator.app.

From the menu item “File” > “New” choose “Services”

Automator-File-New-Service

Now there are 3 steps to be filled out like so:

Automator final setup for "open in textmate" Finder.app context menu itm
First, edit the top so that “Service recieves selected: files or folders in Finder.app“.

Second, add the action “Get Selected Finder Items” from the left column (use the search field to find, then drag selected into the right work area).

Third, add the action “Run Shell Script” to your service. Fill in the following command:

cat | xargs mate

Finally, choose “File” > “Save…” and give it a name like “Open in Textmate”

9 Responses to “How To add “Open folder in Textmate” to Finder Context Menu”

  1. Joe Alba Says:

    Great tip! I’ve been looking for this feature for a while now.

    But for some reason, it isn’t working for me. I followed the steps, but this service does not appear when I right-click a folder.

    I checked my ~/Library/Services folder, and the service I created was saved as ‘Open in TextMate.workflow’

    Got any tips that could help me out? Does your service wind up with the .workflow extension also?

    (I’m running Snow Leopard — upgraded from Leopard, not a fresh install.)

  2. Daniel Says:

    Nice tip, but somehow the folder or file I selected in Finder appears twice in the Textmate drawer. Do you have the same problem?

  3. Jesper Rønn-Jensen Says:

    @Daniel. Actually yes I have the same problem. Please let me know if you come up with a fix !

  4. Barbara Hofmeister Says:

    Google is most popular and the fastest search engine. adding this kind of facilities will increase its popularity.

  5. Adam Says:

    To fix the “double” loading issue:

    In the “Run Shell Script” Automator action, in the “Pass Input” drop down, change from “to stdin” to “as arguments”

    Change the script:

    FROM:
    cat | xargs mate

    TO:
    mate $1

  6. Scott Says:

    Thanks Adam, that solved the double-loading issue for me as well.

    Also, for whatever reason, the workflow wasn’t picking up my $PATH variable, so I actually had to enter:

    /usr/local/bin/mate $1

    as the shell script. Other than that, though, works like a charm!

  7. Open folder in Textmate | Elink Media Says:

    [...] http://justaddwater.dk/2009/12/08/how-to-add-open-folder-in-textmate-to-finder-context-menu/ Share this article [...]

  8. Jeff Says:

    Hey there:

    Thanks for the tip. I’ve written a version of this workflow that uses slightly fewer steps and also works with paths that contain spaces. You can check it out here:

    http://hoyvinglavin.tumblr.com/post/2708978813/opening-folders-in-textmate-via-finder-context-menus

  9. Henrique Says:

    Great tip!

    Using what Adam and Scott sad, but with the argument surrounded by double quotes avoiding problems with path that contain spaces.

    /usr/local/bin/mate “$1″