Using AppleScript to Create an "Application" for Opening a Directory With SublimeText

| Comments

Open a Directory in Sublime Text from the Command Line

Sublime Text is my current editor of choice.

Using Sublime Text it’s very easy to open up a directory/project from the command line, just create a symlink to the subl command and put it in your path.

ln -s /Applications/Sublime\ Text /usr/local/bin/subl

If that doesn’t work, it’s likely that you don’t have the /usr/local/bin directory in your path. If you’re not familiar with how to add things to your path in 10.8+, all you need to do is edit the /etc/paths file as a super user.

That lets you edit individual files from your terminal with a command like:

subl myfile.txt

If you want to open up a directory, just pass it’s name instead of a file (or pass . for the current directory).

Open a Directory in Sublime Text from an “Application” in the Dock

I’ve got a few common directories that I want easy, one-click access to even if I’m not in the terminal. It’s a pain to have to open up the terminal, and type the directory to open up SublimeText, even if I’ve got an alias for it.

A better way is to make those their own “Application” that can be launched via the dock or a quick launch tool like LaunchBar.

Just open up /Applications/Utilities/AppleScript and paste in this AppleScript (edit the directory to point to the dir you want to open with Sublime Text):

do shell script "/usr/local/bin/subl /Users/myuser/Documents/mynotes"

Then try to “Run” the script to ensure it works and opens up your chosen directory. If it works, then “Save” it and choose a File Format of “Application”. This will save it (by default) into your /Applications directory as a one-click target for opening up sublime text to your chosen dir.

You can also customize the icon (rather than the default script) by finding your new application in the /Applications directory, right-clicking on it, and choosing “Get Info”. Then drag a new icon on top of the little icon to the left of the Application name at the top of the panel.

GetInfo Change Icon

If you’re looking for replacement icons (files that end in .icns) there are a number of free resources for free-use icons if you do a little searching.