From Finder to Sublime Text

Posted by on January 17, 2019

At FreeAgent we work on Macs with a good number of us using iTerm2 and some using Sublime Text. Often I find myself in Finder needing to open a file or folder in Sublime Text. The unfun way is to go Finder -> Services -> Open New iTerm Tab Here and then once that opens type subl ..

There’s a couple other ways to do this that are more fun but do require a bit of setup.

A Fun Way – A Service menu item to open directly in Sublime Text

Courtesy of https://maxoffsky.com/maxoffsky-blog/more-sublime-text-2-goodness-tips/.

To set this up open Automator. In the “New” dialog choose Service. In the right pane, for “Service receives selected” choose “files and folders”. For “in” choose “Finder.app”.

On the Library pane on the left click on “Files & Folders” and then drag “Open Finder Items” over to the right pane. From the “Open with” dropdown choose “Sublime Text.app”

Save this workflow. I suggest a name like “Open With Sublime Text”. (As a note – I tried to name it “Open In Sublime Text” and the Service menu item refused to show up. Others didn’t have a problem with that name. ¯\_(ツ)_/¯ )

Now in Finder you can click on a file or folder and, in the menu bar, go to Finder -> Services -> Open With Sublime Text. Wee!!

An Even More Fun Way – A Finder toolbar button

To set this up first open Script Editor. Then paste the below in:

(*
 Open in Sublime Text
 To use:
  * Drag Open In Sublime Text to the toolbar of any finder
  window to add it to the toolbar
*)

on run
    tell application "Finder"
        if selection is {} then
            set finderSelection to folder of the front window as string
        else
            set finderSelection to selection as alias list
        end if
    end tell

    subl(finderSelection)
end run

-- script was drag-and-dropped onto
on open (theList)
    subl(theList)
end open

-- open in Sublime Text
on subl(listOfAliases)
    tell application "Sublime Text"
        activate
        open listOfAliases
    end tell
end subl

(credit for the above to https://github.com/hamxiaoz/open-folder-with-sublime)

Then File -> Export. Change “File Format” to Application. Name it whatever you want and save it to your favorite Application directory.

Then Command+drag and drop this new Application on to your Finder toolbar.

Now you can click on a file or folder and then click your new button! The file/folder will open up in Sublime Text. You can even drag and drop a file/folder on to the new button and it will open!!

“But Pat,” you say, “this new button has the default, boring icon. That’s not fun.”

You’re so right. We can fix that! If you want the icon from Sublime Text, find your Sublime Text.app file. Right click and “Show Package Contents”. Open Contents -> Resources. Scroll down to find the Sublime Text.icns file.

Then in another Finder window find the application you just created above. Hit Command + I to open the file’s Info page.

Finally, drag and drop the Sublime Text.icns file on to the top icon in the Info pane. You should get a green + sign when you have it correct. Once you’ve dropped it the icon of your new toolbar button should automatically change.

In fact, you can put any icon you want here. How fun is that?!

In double fact, neither of these methods to open a file/folder is unique to Sublime Text. It just requires that you know how to open your editor of choice. You should play around with changing these to work with your favorite editor.

Enjoy opening your files and folders in more fun ways! And let me know if I missed an even more fun way to do it.

Leave a Reply

Your email address will not be published. Required fields are marked *