This tool automatically syncs environment variables from ~/.bash_profile to macOS LaunchAgent, making them available to GUI applications and non-shell processes.
When you set environment variables in ~/.bash_profile, they're only available in Terminal sessions. GUI applications (like VS Code, IntelliJ, etc.) launched from Finder or Spotlight don't see these variables.
- Captures current environment variables
- Sources
~/.bash_profileto get new environment - Detects changes and new variables
- Creates/updates a LaunchAgent plist that sets these variables
- Applies changes immediately (full effect after logout/login)
# Run the sync manually
~/bin/sync-env-to-launchctl
# Check what would change without applying
~/bin/sync-env-to-launchctl --dry-run
# See detailed output
~/bin/sync-env-to-launchctl --verboseInstall the LaunchAgent to automatically sync when ~/.bash_profile changes:
# Copy the LaunchAgent to the proper location
cp ~/g/svalka/bin/com.user.sync-env.plist ~/Library/LaunchAgents/
# Load it
launchctl load ~/Library/LaunchAgents/com.user.sync-env.plist
# Verify it's running
launchctl list | grep sync-envNow whenever you edit ~/.bash_profile, environment variables will sync automatically within 10 seconds.
- Edit
~/.bash_profileas normal - Save the file
- Within 10 seconds, new variables are available to newly launched apps
- For complete effect (all running apps), log out and log back in
# See sync activity
tail -f /tmp/sync-env.log
# Check for errors
tail -f /tmp/sync-env.error.log# Check if environment plist exists
ls -la ~/Library/LaunchAgents/com.user.environment.plist
# Check if sync agent is loaded
launchctl list | grep com.user.sync-env
# Manually reload the environment agent
launchctl unload ~/Library/LaunchAgents/com.user.environment.plist
launchctl load ~/Library/LaunchAgents/com.user.environment.plist
# See what environment variables are currently set
launchctl getenv PATH- Smart detection: Only syncs variables that changed after sourcing
.bash_profile - Exclusions: Automatically excludes shell-specific variables (PS1, HISTSIZE, etc.)
- Backup: Creates timestamped backups before updates
- Validation: Checks plist syntax before applying
- Dry-run mode: Preview changes without applying
- Immediate effect: Variables available to new apps right away
The tool automatically excludes:
- Shell internals (BASH_*, SHELL, PWD, etc.)
- History variables (HIST*)
- Prompt variables (PS1-PS4)
- Terminal settings (COLUMNS, LINES, TERM)
- Functions
- Changes apply to newly launched applications immediately
- Running applications won't see changes until restarted
- For system-wide effect, log out and log back in
- The tool creates backups in
~/Library/LaunchAgents/com.user.environment.plist.backup.*
# Stop automatic sync
launchctl unload ~/Library/LaunchAgents/com.user.sync-env.plist
rm ~/Library/LaunchAgents/com.user.sync-env.plist
# Remove environment variables
launchctl unload ~/Library/LaunchAgents/com.user.environment.plist
rm ~/Library/LaunchAgents/com.user.environment.plist
# Remove the tools
rm ~/g/svalka/bin/sync-env-to-launchctl
rm ~/g/svalka/bin/com.user.sync-env.plist
rm ~/g/svalka/bin/README.md