mac-setup
mac-setup copied to clipboard
Setting environmental variables
I'm Submitting a ...
[ ] Bug report
[x] Tool/language/etc documentation request
Tool/Language/etc
Setting environmental variables (especially ones that gets picked up in non-terminal launched apps) seems to be a bit of a challenge?
Best I can find seem to be the top answer of this SO post using environment.plist
.
Other Information
Happy to write this up, just want to check there isn't an obviously better way to do this.
I'm not sure what you mean. Can't you just export them in your bash/zshrc/etc config?
Like this: export GOPATH="$HOME/repos/go"
Could you give an example of such a environment variable?
As far as I can tell, the trick is to get access to those variables when launching apps from Spotlight or the Dock, as .bash_profiles
etc. are ran when you Terminal.app or iTerm.app etc.
Example:
- I type
export FOO="foo"
in iTerm - Launch Emacs from the dock
- Launch eshell, and
echo $FOO
: this gets nothing.
The SO post I linked to seems to fix this.
Sounds good to me if you want to write it 👍 Be sure to read our contribution docs.
I think @shen-tian is right: native Mac apps launched from the Dock or by double-clicking their icons do not get launched via a login or interactive shell, so none of the user shell startup scripts are run in that context. (In fact, I think it skips all shell startup files, so there's nothing you can do at the shell level to set environment variables.) Hackery like that linked SO posts is the way you have to do it.