Emacs: Getting Environment Variable When Launching Emacs from GUI

On Windows or Mac, when you launch emacs from desktop, often the environment variables are not inherited. How to solve this?

On Windows, you need to set them in Registry. You can do that using command line (setx in “cmd.exe”) or GUI (“SystemPropertiesAdvanced.exe”). see Windows Environment Variables Basic Tutorial.

On Mac, you need to set a file 〔~/.MacOSX/environment.plist〕 See: Source developer.apple.com

thx to Adam Jiang for asking.