Sometimes you need an application that you launch from the Dock or Launchpad — anywhere other than the terminal — to run with a custom path.
Normally, applications start with an extremely limited path:
But if you are running an editor or an IDE like WebStorm or Visual Studio Code, it might need to use various executables (compilers, linters etc.) which have to be on the path but are installed elsewhere, like somewhere in your home directory.
In particular, I have this issue with running Elm-related commands like
elm (the compiler),
elm-test and so on in Visual Studio Code. The Elm extension in theory allows me to specify paths to
these, but in practice it doesn’t work.
The “official” workaround is to add Visual Studio Code executable to the path, and then always
start it from the terminal by running
code. This is because in a shell, there are many ways
to control the
PATH environment variable.
But not so for applications started any other way. I tried everything I could find:
etc/paths.d(this only applies to the shell)
/etc/launchd.confwith appropriate commands (doesn’t work)
launchctl setenv PATH <path>in my
~/Library/LaunchAgents/startup.plistto run this command (doesn’t work)
launchctl config system path <path>(doesn’t work).
Side note: you can examine the environment variables of a running process with this command:
ps eww -o command <pid> | tr ' ' '\n'
So finally, I came up with a hybrid approach. I noticed that macOS Automator can create an application, and in the workflow, I can run a shell script. So this should give me the ability to control the path, and also have an icon sitting in the Dock (although all this effort wasn’t for the purposes of putting an icon in the Dock; I’m trying to open projects in VSCode using an application called Workspaces).
This actually works!
zshso for me it’s:
source /Users/alex/.zshrc && code $1
(when Workspaces launches this application, it passes a directory
for VS Code to open as the argument; this is what
It appears that another option for creating a launcher would be Platypus, which allows you to create applications from scripts. However, I haven’t tried it.