pdef generates patch script of Mac OS X User Defaults (property list).
Before and after you set any environmental settings from GUI, please write out property lists to files.
pdef generates a shell-script with comparing files of a property list.
Next time you set the same environmental settings, you only execute the shell-script without manipulating GUI.
$ brew install yammerjp/tap/pdef
$ defaults read > before
# Set any settings on GUI
$ defaults read > after
$ pdef before after > path/to/file
$ git clone https://github.com/yammerjp/pdef.git
$ cd pdef
$ make
# built binary is on bin/pdef