Opening a directory in TextMate from Finder

I love TextMate. I love being able to load in a directory as a project, like I do with a lot of my rails applications. When I’m using Finder to navigate my filesystem, I sometimes want to open a directory into TextMate from Finder, and a contextual menu would be perfect.

Using some knowledge of Automator, this can be done quite easily.

Automator Steps

The first thing to do, launch Automator. Automator allows you to create quick scripts by giving you a building-block approach for common things you might like to do. To accomplish our task, we need two of these building blocks.

Step 1: Get Selected Finder Items.

The first thing that we need to do is get our selected Finder item, our directory that we want to open. You can find this block by typing “Get Selected Finder Items” in the search bar or by searching the Library for Applications > Finder. Now drag this bar into the workflow area. That’s all we need for step 1.

Step 2: Open the selected item in TextMate.

This step is going to require something more than just dragging an element over, as we are now going to mix some Automator with some bash to get the job done. Find the “Run Shell Script” action in Library under Application > Automator.

When you do this, you will see that the textarea already has a command for us: cat. We want to add something to that command so that it reads cat | xargs mate.

Open with Textmate

NOTE: TextMate comes with a command line tool, called mate. You will need to make sure that mate is setup to work in terminal.

Saving the Workflow as a Contextual Menu

If you chose to run this script on a selected directory it should work. Now we need to save this workflow. Go to the menu bar and select File > Save As Plug-in…

Now create a nicely defined name for this script, like “Open in TextMate” and make sure that the plug-in is Finder. Hit the Save button.

In Finder, find a directory that you would like to open in TextMate. Right click this directory. In the menu that appears, you should see an Automator menu, and inside of that, you will find the script that you created. Just click that contextual menu and you will now have a shortcut to opening projects in TextMate.

Finally, you can download the workflow and save it for yourself.

  • kennyd

    I followed the directions exactly, and when I try running the workflow I get an error “workflow failed”. I tried running “mate somefile” on the command line just to make sure its set up right, and it is. Any ideas on what else could be busted?

  • http://shifteleven.com Adam

    Hmmm…I am not sure. What you can do is use Library > Automator > View Results and try to get something from that.

    In addition to that, I’m going to upload my script.

  • http://www.nathanielbibler.com Nathan

    Most likely you need to change the script to read:

    cat | xargs /usr/local/bin/mate

    Automator is not picking up your PATH when it attempts to execute the shell script.

  • http://geekthang.com FredB

    Hi,

    I made some contextual menu items to do this and other things, they require the excellent OnMyCommand. You cand find the commands in the TextMate svn repository under /trunk/tools/CM/.

    You can even use Shortcuts to assign shortcuts to contextual menus.

    Here is a short list of the commands, see the readme for more info and how to install.

    -Open in TextMate
    -New TextMate file here
    -New TextMate file here (alt)
    -New TextMate file here with Clipboard text
    -Open selected text in TextMate
    -Set type and creator to TextMate
    -Edit OMC commands in TextMate
    -List folder content in TextMate
    -List pkg content in TextMate

    Anyway, for those commands or anything else, if you don’t know them, you should check OnMyCommand and Shortcuts.

  • http://josh.gourneau.com joshg

    A great simple app for doing this can be found at :
    http://manas.tungare.name/software/finder-toolbar-scripts/

  • http://www.namaless.com/ Namaless

    I found in this directory:

    sudo ln -s /Applications/TextMate.app/Contents/SharedSupport/Support/bin/mate /usr/bin/mate

    I have MacOSX Snow Leopard and Updated version of TextMate.
    Please check.

  • http://reviewsnewspaper.com NANCY STANTON

    cool great website yea nice work our website will soon be adding reviews on blogs and add them to our websites as the top best 10 blogs to visit we also do reviews on product recalls all types of reviews we will get back to you

  • http://www.wlmblockcheck.com triople block checker

    Hey MSN Freaks! How are you? visit this blockcheck site!

  • Pingback: justaddwater.dk | How To add “Open folder in Textmate” to Finder Context Menu

  • http://www.anildewani.com Anil Dewani

    This helped me in one of my projects. You rock!

  • http://www.cleanerccc.com/ adware away

    When you’re a real estate agent, you are your own brand. It’s your own reputation, your own name, on the line. And it’s sad that some people don’t seem to care.

  • angie

    09308900189, i need textmale. 18-30y/o lang po…

  • laire

    hi slhat nid koh poh txt mate
    wehhhhhhhhhhh

    sun kopoh
    09333993290
    globe kopoh
    09053284421

    gay poh meh eh xencya

  • http://www.rtakitchencabinets.com/ RTA Kitchen Cabinets

    Very good desgin of this internet site. It can be person and compares in your posts. Don´t give up and make your own point!

  • http://www.syntha6.org Tuan Beauharnois

    What a blog post!! Very informative and also easy to understand. Looking for more such writeups!! Do you have a myspace or a facebook?
    I recommended it on stumbleupon. The only thing that it’s missing is a bit of new design. Anyway thank you for this blog.

  • http://youshouldseo.com Web Design Dallas

    Glad I found this article on yahoo when I was surfing the web. Good STUFF!

  • Jeff

    I’ve got a Snow Leopard version of this process online here:

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

    Works with paths that contain spaces.