global environment variables (like PATH) in mac os x via environment.plist and /etc/launchd.conf

so, through my journey of getting emacs 23 and conkeror to work on mac os x, i’ve discovered that PATH is not defined for native mac gui apps. details of the journey can be found in this post of mine’s.

now, to sum it up, to get PATH or other env variables working in mac gui apps, you need to create or modify your ~/.MacOSX/environment.plist file. i usually define my PATH in .bashrc, so i do something like

In terminal, type:

<pre class="src src-sh">defaults write ${<span style="color: #eedd82;">HOME</span>}/.MacOSX/environment PATH <span style="color: #ffa07a;">"${PATH}"</span>

then restart (log out) computer to take effect.

To update the path of environment.plist at every login, do (credit here):

<pre class="src src-sh"><span style="color: #00ffff;">if</span> [ -x /usr/libexec/path_helper ]; <span style="color: #00ffff;">then</span>

eval /usr/libexec/path_helper -s defaults write $HOME/.MacOSX/environment PATH “$PATH” fi

in /etc/profile

logout and log back in. however, apps launched using spotlight still do not see the env vars. they are seen only when launched using Finder. so, to fix that, put something like

 <pre class="src src-sh">setenv PATH /opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin:/usr/X11R6/bin:/Users/vinh/Documents/bin/:/opt/local/bin:/opt/local/sbin:/usr/texbin

in your /etc/launchd.conf file. a restart is required. this second method works for all apps start in mac.

these files should be edited each time u add to your PATH in .bashrc.

see my original post to follow all the credit.

Emacs App (v 23) for Mac OS X & environment.plist

Ever since i bought my macbook i’ve been using carbon emacs (v 22) as my emacs of choice since it has everything emacs and works well with OS X (I didn’t want to use Aquamacs because I’m more of a unix person than Mac).

Recently, I discovered Emacs App and wanted to migrate over since

  1. it is emacs v 23, and
  2. it uses Cocoa, a newer technology than carbon and is the standard on Mac OS X these days.

I wanted to use Vincent Goulet’s modified binary version of Emacs App, however, ESS gives me weird characters. Thus, I decided to just compile Emacs App myself.

  1. Downloaded emacs app source via CVS.
  2. ./configure –with-ns
  3. make
  4. make install

Step 3 will make Emacs.app in ./nextstep/. Now, install ESS (ESS: download and put in ~/elisp, edit .emacs for load) and AucTeX. AucTeX:

  1. ./configure –with-emacs=~/Downloads/emacs/emacs/nextstep/Emacs.app/Contents/MacOS/Emacs –with-lispdir=/usr/local/share/emacs/site-lisp –with-texmf-dir=/usr/local/texlive/texmf-local/
  2. make
  3. sudo make install

ESS works. However, AucTeX doesn’t because it doesn’t see the PATH to latex/pdflatex. This is because Emacs.app acts like a Mac program, so it doesn’t have access to it as defined in my .bashrc. To do so, we must edit/make ~/.MacOSX/environment.plist , a file that is analogous to .bashrc but for Mac GUI programs.

FIX (http://www.emacswiki.org/emacs/CarbonEmacsPackage [unix and mac path] ) In terminal, type: defaults write ${HOME}/.MacOSX/environment PATH “${PATH}”

then restart (log out) computer to take effect.

To update the path of environment.plist at every login, do (credit here): #/etc/profile begin

if [ -x /usr/libexec/path_helper ]; then eval /usr/libexec/path_helper -s defaults write $HOME/.MacOSX/environment PATH “$PATH” fi

#/etc/profile end

in /etc/profile

UPDATE 2: it appears launching emacs 23.1 through spotlight will not pick up the ENV variables. launching through Finder or the shell is fine. Don’t know why. this is weird!

UPDATE 3: did some googling about environement variables, and this, this, and this site taught me how to fix the PATH issue when launching using spotlight. So i just need to put the following in my etc/launchd.conf file: setenv PATH /opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin:/usr/X11R6/bin:/Users/vinh/Documents/bin:/opt/local/bin:/opt/local/sbin:/usr/texbin

restart computer and things should be working GREAT!

i usually update my PATH in .bashrc, so whenever i update it, just echo $PATH and update the launchd.conf file.

another way to fix all this is to set the PATH (exec-path) inside .emacs, like here.