I needed to change my printer's advanced print setup automatically with AppleScript. AppleScript doesn't support this feature, so I found a way to do it with a shell script. First, create and save a custom settings preset in the printing dialog. For this example, assume those settings are named Preset1. Then, in the AppleScript Script Editor, enter the following code:
do shell script
"defaults write com.apple.print.custompresets
com.apple.print.lastPresetPref Preset1"
This way, the Preset1 settings will be used next time you print.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20070312100620242