How can I script Preferences changes in an application?
Use UI Scripting:

http://www.macosxautomation.com/applescript/uiscripting/index.html

https://stackoverflow.com/questions/7896680/using-applescript-to-click-the-plus-button-in-a-preferences-window

How to know the name of UI elements using Accessibility inspector (or any other tool)