Hacking environment.plist

brian_d_foy on 2002-11-12T23:13:04

Recently I needed to set some environment variables for a little project I was doing in BBEdit. Aqua applications do not really care about whatever shell I use in the terminal, so they do not read my login files.

Mac OS X does; however, read the ~/.MacOSX/environment.plist file when I log into my account. That environment is available to all applications.

Since I do not like to maintain the same information in two places, I made a short script to turn my shell environment into my environment.plist. I added a short function to Mac::PropertyList to turn a simple hash into a plist (I have not fully implemented the pieces to turn an arbitrary data structure into a plist, though).

#!/usr/bin/perl

use Mac::PropertyList;

print Mac::PropertyList::create_from_hash( \%ENV )


From that I get a plist, which I can save as ~/.MacOSX/environment.plist. I edited the output a bit to give you a flavor of the final plist. You can edit plists by hand or with the PropertyListEditor application.





        POP_USER
        comdog
        HISTFILESIZE
        3000
        RSYNC_RSH
        /usr/bin/ssh -l comdog
        PWD
        /Users/brian/Desktop
        CVSROOT
        /Users/brian/.cvs
        HOST
        g3.home.staceytappan.com
        EDITOR
        /usr/bin/vi
        PATH
        /bin:/usr/bin:/sbin
        SHELL
        /usr/local/bin/bash
        CVS_RSH
        ssh
        USER
        brian
        HOME
        /Users/brian




At some point I can extend this to automatically recognize when my shell environment has a permanant change (e.g. .bash_profile changes) and then regenerate the environment.plist. I still have to log out and log in again for the changes to take effect, so I have to figure out how to hack that some time. If I can figure that out, I can make the process happen through some sort of scheduler magic or create a tool to "source" the plist.