Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Tuesday November 12, 2002
06:13 PM

Hacking environment.plist

[ #8915 ]

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).

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.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
        <string>/usr/bin/ssh -l comdog</string>

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.