Kenneth Friedman
December 26, 2018

Sublime Text — especially on the Mac — is known to be a super simple, easy text editor. It loads fast, and it's fairly minimal. Whenever I want to quickly open a text file or a small program Sublime is my go to choice.

The Problem

To quickly inspect files with Sublime Text, I need to be able to open any given file in Sublime from the Mac Finder.

Finder does have the notion of a "Default Application", but there are two problems. First, it works at a per file-extension level. You can assign a particular file type to open with a default application, but you can't assign all files to have one default application. Second, there can be only be one default application, which is problematic when you have a files that need multiple apps. For example, with an HTML file, it is best to open with a text editor to modify the file, but it's best to open in a browser to actually view the file.Why do websites need a separate editor and viewer? Don't get me started. Why isn't the authoring always on?

A Flaw in the Obvious Solution

Finder's "Open With" menu.

Luckily, Finder has a context menu (right clicking on a file), that includes an "Open With..." submenu. This menu lists some of the possible applications that can open the given file type. At first, I tried adding a keyboard shortcut to this Finder menu option. Adding keyboard shorcuts is very easy on the Mac... you can provide the exact name of the menu item, and then attach a key command to it. Because the default application uses "Cmd+O", it makes sense that the secondary application should be "Shift+Cmd+O."

Finder trying to find applications that can open this file.

Unfortunately, the list of possible "Open With..." items is generated on the fly, when the user clicks or hovers on the menu item. You can see this very briefly, when the list is empty and the menu says "Fetching..." When the standard keyboard shortcut is invoked, it looks for the exact menu item "Open With...Sublime", but since the list isn't populated, it can't find it, and the shortcut doesn't run.

The Real Solution

The secret lies with Services. Services is another great Mac feature that allows you script applications. I created a Service using Automator. The Service is always available, preloaded, in the Finder menu. (Under Finder->Services).

The Service (now called Workflow in Automator) is very simple. As shown below, it simply takes the currently selected files or folders in Finder, and opens them in Sublime. Easy!

Then, the Service can be "installed" by saving the file to ~/Libary/Services/

Finally, the installation makes it available in Finder's Service menu. Therefore it is easy — once again — to attach a keyboard shortcut to the Service, which opens the currently selectedd file or folder in Sublime.

Now — using this Automator Service and Keyboard Shortcut combination — I can open any text file in Sublime with a simple Shift+Command+O keyboard shortcut.