How to make "Open in Sublime2" on MAC

I like Sublime Text 2 and I've been using it recently for almost all development. Well, after watching these tutorials I like it even more.

Just one very timesaving thing isn't very clear. How to make a shortcut to open files/folders from context menu. Although, it's part of one of the videos above I think there's a little mistake. Ok, so this relates only to the Mac and OS X users. Sorry I don't know if you can do the same on Windows.

Adding "Open in Sublime2" context menu option

Open Automator from Applications folder or from spot-light.

Press ⌘N (CMD + N or in menu File -> New) and select Service.

In actions list on the left, double click or drag & drop Run Shell Script to the right.

Inside the textarea paste:

/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl -n $@

This -n options tells Sublime2 to open a new project every time you use it on a file or a folder. $@ is list of arguments (selected files and folders).

In Service receives selected choose files or folders.

In Pass input choose as arguments.

(Both options are marked with rectangles in this image)

Now press ⌘S (CMD + S or in menu File -> Save a Version) and choose a name (eg. "Open in Sublime2"). This name will appear in context menu.

Now when you right-click on a file or a folder you should see you service at the bottom of the context menu.

You can also open entire folder in exactly the same way.

Keyboard shortcut for "Open in Sublime2"

Note: This works only with files.

To be honest I was surprised how easy is to make a keyboard shortcut in OS X.

Open System Preferences -> Keyboard. Click on Keyboard Shortcuts tab on the top of the window.

Then choose Services from the left menu and find "Open in Sublime2" in the right list. When you click on it you should see "add shortcut" button. Click the button and you can press what keys you want to use as a shortcut.

Honestly, I don't know why this works only with files and not folders.

Removing "Open in Sublime2"

If you want to just temporarily remove this service from context menus open System Preferences -> Keyboard and click on Keyboard Shortcuts tab in the top of the window.

Then choose Services from the left menu, find "Open in Sublime2" in the right list and uncheck a checkbox on the same row on the left.

To permanently remove your own services that you don't want to useany more navigate to ~/Library/Services/ where each *.workflow represents one service.

Open in Sublime2 from shell

This is very simple, just make a symlink for bin/subl in Sublime2 application bundle.

sudo ln -s /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl /usr/bin/subl

Of course, you can name your link as you want.

Now you can call just subl my_file.txt from shell and it will open Sublime2 window.

blog comments powered by Disqus