Created
October 24, 2013 13:11
-
-
Save tbuckel/7137034 to your computer and use it in GitHub Desktop.
Mac OS: Setting the environment for new processes started by Spotlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/3756686 | |
Setting the environment for new processes started by Spotlight | |
You can set the environment used by launchd (and, by extension, anything started from Spotlight) with launchctl setenv. For example to set the path: | |
launchctl setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin | |
Or if you want to set up your path in .bashrc or similar, then have it mirrored in launchd: | |
PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin | |
launchctl setenv PATH $PATH | |
There's no need to reboot though you will need to restart an app if you want it to pick up the changed environment. | |
This includes any shells already running under Terminal.app, although if you're there you can set the environment more directly, e.g. with export PATH=/opt/local/bin:/opt/local/sbin:$PATH for bash or zsh. | |
Changes will be lost after a reboot | |
To keep changes after a reboot you can set the environment variables from /etc/launchd.conf, like so: | |
setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin | |
launchd.conf is executed automatically when you reboot. | |
If you want these changes to take effect now, you should use this command to reprocess launchctl.conf (thanks @mklement for the tip!) | |
egrep -v '^\s*#' /etc/launchd.conf | launchctl | |
You can find out more about launchctl and how it loads launchd.conf with the command man launchctl. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment