Change Mac GUI app environment variable
Application launched from finder on mac does not respect environment variables set by bash. Here are some methods to set environment variables for GUI applications.
Simplest method: modify via bash
launchctl setenv NODE_ENV development
More customizable: modify plist file
- Open the app by right clicking Show Package Content
- Edit Info.plist file. Add following section
- Restart Finder by killall Finder in terminal.app
<key>LSEnvironment</key> <dict> <key>NODE_ENV</key> <string>development</string> </dict>
A caveat here is: Editing this file only have effect before the app is launched the first time. Then launch service is going to cache this. Use this command for update to take effect.
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f myapp.app
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user killall Finder