Open Sublime Text 3 from Terminal on Mac OS X

I find myself relying more and more on Sublime Text for my coding needs and as such I’m always on the lookout for a shortcut for my everyday Mac needs (as you guys know from my AppleScript shortcuts a while back).

Here’s a quick way to launch your files/folders from Terminal in Sublime.

Assuming you’ve installed Sublime Text 3 correctly on your Mac, this following command should open the app from Terminal :

$ open /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl

If that works, you’re good to go.

Step 1 : Create a symlink called sublime 

$ ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime

Step 2 : Check that your system profile can find the symlink you just created.

$ open ~/.bash_profile

Step 3 : Add both these lines in if they’re not already in here & then save the file :

alias sublime="open -a /Applications/Sublime\ Text.app"

export PATH=/usr/local/bin:$PATH

Step 4 : Reload your bash_profile :

$ source ~/.bash_profile

Done ! You can now navigate to any of your code/script folders in Terminal and open them in Sublime with the following commands :

sublime .
sublime trial.js
sublime foldername
Advertisements

3 thoughts on “Open Sublime Text 3 from Terminal on Mac OS X

  1. Hello!!!
    I’m getting an error after I’m typing this:
    ln -s “/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl” /usr/local/bin/sublime
    The error message is:
    ln: /usr/local/bin/sublime: Permission denied
    Any thoughts?
    Thank you

    • I found the problem!!!!!
      I just added sudo at the beginning and it worked!
      And one more thing that didn’t worked for me is in this code:
      $ open /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/sub
      I needed to enter an “l” (L in lowercase) at the end “subl”
      Thanks anyway!!!!

Leave a message :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s