Last active
February 16, 2026 17:03
-
-
Save MrPandir/d591a6f372fc4cbd835fd214825a3070 to your computer and use it in GitHub Desktop.
Setting environment variables globally on MacOS at login.
This file contains hidden or 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
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>Label</key> | |
| <string>my.startup</string> | |
| <key>Program</key> | |
| <string>/Users/user/.config/login_setenv.sh</string> | |
| <key>RunAtLoad</key> | |
| <true/> | |
| </dict> | |
| </plist> |
This file contains hidden or 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
| #!/bin/sh | |
| launchctl setenv XDG_CONFIG_HOME $HOME/.config | |
| launchctl setenv XDG_DATA_HOME $HOME/.local/share | |
| launchctl setenv XDG_STATE_HOME $HOME/.local/state | |
| launchctl setenv XDG_CACHE_HOME $HOME/.cache | |
| launchctl setenv XDG_RUNTIME_DIR $TMPDIR | |
| launchctl setenv ZDOTDIR $HOME/.config/zsh | |
| launchctl setenv TERMINFO $HOME/.local/share/terminfo | |
| launchctl setenv TERMINFO_DIRS $HOME/.local/share/terminfo:/usr/share/terminfo | |
| launchctl setenv WAKATIME_HOME $HOME/.local/share/wakatime |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Guide
environment.plistinto the directory~/Library/LaunchAgentslogin_setenv.shwherever you like.chmod +x login_setenv.shenvironment.plistfile, replace/Users/user/.config/login_setenv.shwith the actual path to yourlogin_setenv.shfile.Useful commands
Note
501 is your current user ID (UID). You can get it with the command:
id -ulaunchctl bootout gui/501/my.startup→ Unloads / stops the service (removes it from running state)
launchctl bootstrap gui/501 ~/Library/LaunchAgents/environment.plist→ Registers / loads the plist into launchd (makes the service known to the system)
launchctl kickstart gui/501/my.startup→ Immediately starts the service (even if it has no KeepAlive / RunAtLoad)
launchctl print gui/501/my.startup→ Shows detailed status and properties of this particular service
launchctl print gui/501→ Shows all services and their state for current user domain
launchctl list | grep -i my.startup→ Shows whether the service is currently loaded and its PID (if running)
launchctl getenv XDG_CONFIG_HOME→ Shows the value of environment variable from launchd's perspective
printenv | grep -i '^XDG_'→ Shows all XDG_* variables visible in the current shell