How can I script Preferences changes in an application? I want to use applescript to change a checkbox in the preferences box of Safari. I can open the preference window, but how to code the check box change?

Example: I'd like to toggle the check box for "Block pop-up windows" on tab "Security" of the preferences 

tell application "Safari" to activate
   tell application "System Events"
      keystroke "," using command down
   end tell
   --some magic goes here
end tell
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)