When starting Emacs.app on Mac, the Emacs doesn't have some environment variable set correctly. Typically it is terrible when you use GPG, pinentry-mac, gpg-agent But also a lot of different variables used to make git works correctly, etc...
-
Create the file
~/bin/init-app-env.sh
:#!/usr/bin/env zsh source ~/.zshrc for i in $(export); do var=$(echo $i|sed 's/=.*//') val=$(echo $i|sed 's/^[^=]*=//') [[ $val != "" ]] && { launchctl setenv $var $val } done
If you use bash you can safely replace zshrc by bashrc in the script.
-
Create a file
~/Library/LaunchAgents/com.user.loginscript.plist
(replace ME by your login name):<?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>com.user.loginscript</string> <key>Program</key> <string>/Users/ME/bin/init-app-env.sh</string> <key>RunAtLoad</key> <true/> </dict> </plist>
-
Run in a Terminal
launchctl load ~/Library/LaunchAgents/com.user.loginscript.plist
Congrats!
Now at each login the script will run with your zsh environment. Beware, it can take a few seconds before the script is launched. So don't rush to launch Emacs.app just after login.