Sublime Forum

OSX: how to use the subl command to open a local installation of ST

#1

Hello everyone! First post here I hope I’m in the right category :slight_smile:

I have a case where, on my school computers, I’d like to use the subl command to open a local install of the Sublime Text.app that lives in my home folder (OSX). It might happen depending on the computer that another install of Sublime (which is not up to date) resides in /Applications, but in any case, when I try to use the subl command it’ll always try to open the version in /Applications, even if it doesn’t exist.

Here are the steps I took for now:

  • Install Sublime Text.app in ~/.local
  • Symlink’d the subl command: ln -s ~/.local/Sublime\ Text.app/Contents/SharedSupport/bin/subl ~/.local/bin/subl
  • Added the ~/.local/bin folder to my path (in front of anything else)

This unfortunately doesn’t work. Running the app from my local folder works fine if I open it from the Finder however.
If you guys know a fix or need more information feel free to reply!

Thanks a lot for your attention.

Edit/ additional information

$ where subl
~/.local/bin/subl

Running subl when ST is not installed in /Applications

$ subl
Unable to find Sublime Text

What the symlink looks like:

$ ls -l ~/.local/bin
subl -> ~/.local/Sublime Text.app/Contents/SharedSupport/bin/subl
0 Likes

#2

Are you trying to have multiple instance of Sublime Text running at the same time?

0 Likes

#3

Hello, thanks for the quick reply.

I am not, I’m only trying to run the install from my home, and forgo the install from /Applications altogether.

I’ve added more information to my first post.

0 Likes

#4

What is the result of:

which subl
0 Likes

#5

Here you go:

$ which subl
~/.local/bin/subl
0 Likes

#6

So I looked and we use NSWorkspace URLForApplicationWithBundleIdentifier to find the app to launch. I don’t know the details of Apple scans for bundle identifiers (they are in the .app), but my hunch is by default the /Applications and ~/Applications paths.

Is there a reason you don’t use ~/Applications? That is personally what I use since I have scripts that regularly stage new releases and I don’t want to prompt for root permissions every time I stage a file.

0 Likes

#7

Is there a reason you don’t use ~/Applications ?

Yes, the .local folder is actually a disk image (which doesn’t reside on the same volume as my home) that I mount when starting a session, as our home sessions at school are rather limited in space.
Maybe I should’ve said so in my original post haha, just didn’t think about it.

In any case, it’d be nice if we could specify a custom install folder for the subl command somehow.

0 Likes

#8

I think the solution is to figure out how macOS find applications by bundle id from custom locations. There may be more experienced Mac users here than know the answer to this.

0 Likes

#9

Alright, thanks for your help anyway! My workaround is just starting the app from the finder for now.

0 Likes

#10

It’s not an equivalent solution, but depending on exactly what you need subl to do, you may be able to use the “open” command with the -a flag to specify the location of your app bundle.

I can open files in ST3 with something like

open -a "/Applications/Sublime Text.app" ~/backup.log

or

open -a "/Applications/Sublime Text.app" ~/*.log
0 Likes

#11

Good idea, thanks!

0 Likes