1

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/python@3.8/bin:/usr/local/opt/python@3.8/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?

Alex
  • 41,580
  • 88
  • 260
  • 469
  • Show output from `ls -al /usr/local/bin | grep sublime` please. Also output from `echo $PATH`. – matt Jan 15 '21 at 07:15
  • Seee updated question with the "proof" – Alex Jan 15 '21 at 07:19
  • It's interesting that it's owned by `root`. That seems wrong but I don't see how it would hurt anything. – matt Jan 15 '21 at 07:38
  • Yes, saw that too, changed that to my user - but still does not change the outcome. I still get the same error – Alex Jan 15 '21 at 07:43

1 Answers1

4

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
Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
  • `open -a sublime` does not work to begin with, neither `open -a subl`. – Alex Jan 15 '21 at 07:45
  • 1
    But `alias sublime="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"` is working – Alex Jan 15 '21 at 07:46
  • @alex Right! This is because the application name is "Sublime Text" not "Sublime", change accordingly... – Jean-Baptiste Yunès Jan 15 '21 at 07:50
  • @alex don't link to executable directly, prefer using the *name* of the app – Jean-Baptiste Yunès Jan 15 '21 at 07:53
  • @Jean-BaptisteYunès `Sublime Text.app/Contents/SharedSupport/bin/subl` is the command-line utility that users are *supposed* to link to. The actual macOS binary is located elsewhere, `subl` is just a script that invokes it properly. – MattDMo Jan 15 '21 at 23:35
  • adding 'subl@ -> /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' to /usr/local/bin worked. adding 'sublime@ -> /Applications/Sublime Text.app/Contents/MacOS/sublime_text' did NOT. Ty for this – jes516 May 04 '22 at 18:06