4

Opening a directory in TextMate from Finder

Posted in Mac OS X at September 17th, 2006 /

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.

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.

4 Responses to “Opening a directory in TextMate from Finder”

  1. September 23rd, 2006 at 6:23 pm #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?

  2. September 25th, 2006 at 8:23 pm #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.

  3. September 26th, 2006 at 5:59 am #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.

  4. December 18th, 2006 at 2:01 pm #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.

Leave a Reply