Alex
Alex

Reputation: 44275

How to fix opening sublime from terminal in MacOS?

I want to be able to open the sublime text editor in MacOS (14.10.6) from the command line. I found several instructions how to do that (HERE and HERE), but of course it does not work for me.

I did create the symbolic link to the application in /usr/local/bin:

sublime -> /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl

The file at location /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl does exist. Also, the folder /usr/local/bin is included in the actual definition of PATH.

However, the command is not found when I enter it on the command line in a terminal

~$ sublime
-bash: sublime: command not found

Proof:

$ls -al /usr/local/bin | grep sublime
lrwxr-xr-x    1 root    admin        63 Jan 15 07:44 sublime -> /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl

$ echo $PATH
/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/bin:/Users/adietz/miniconda3/bin:/usr/local/bin:/Users/adietz/.pyenv/shims:/Users/adietz/opt/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/puppetlabs/bin:/opt/X11/bin

Any ideas how to fix that?

Upvotes: 1

Views: 3638

Answers (1)

Jean-Baptiste Yunès
Jean-Baptiste Yunès

Reputation: 36391

You may use the open command, as the manual says:

DESCRIPTION

The open command opens a file (or a directory or URL), just as if you had
double-clicked the file's icon. If no application name is specified, the
default application as determined via LaunchServices is used to open the
specified files.

Option -a is suitable for MacOS applications, then

open -a sublime\ text

(or alike) should work.

You can then alias it and call it when needed:

alias sublime="open -a sublime\ text"
sublime

Upvotes: 6

Related Questions