GUI Checkboxes (If Exists syntax)

Hello! I’m still playing with the GUI scripting, and all is going pretty well… a few points linger, however, and I was hoping someone could throw me a bone.

Question #1:
The script below is working great and does everything I need it to do, unless someone has already clicked the checkbox… if the checkbox has already been pressed, it still gets pressed anyway. I know there has to be an If Exists statement that can check the current state of the checkbox and only execute a click if the box has a ‘no’ value. Now, I know the Dock can easily be scripted with the defaults command, but the Dock plist is pretty simple (unless to try to mess with the actual items on the dock), but other Preference Panes’ plists are much less forgiving.


-- Open Dock --

tell application "System Events"
	tell process "System Preferences"
		click menu item "Dock" of menu "View" of menu bar 1
	end tell
end tell

-- Apply Dock --

delay 2

tell application "System Events"
	tell process "System Preferences"
		set value of slider 2 of front window to 0.125
		click checkbox "Magnification:" of front window
		set value of slider 1 of front window to 1
	end tell
end tell

Question #2

Has anyone actully tried and succeeded in writing a script that, in Mac OS X 10.3.x, can change the desktop picture to a specific file. If you look at the plist for the desktop (com.apple.desktop.plist) in the Property List Editor you can see the filepath of the currently selected picture, but due to the hiarchy of that plist, I have not yet figured out how to change it through Defaults and the Pane is so complex that I have not figured out how to Click the image using GUI scripting.

so, why script such trivial things to begin with? well, I am about to rebuild about 100 Macs and they all have to be configured the same. I have tried doing clones and disk images and have run into so many issues with permissions and things not working the way they should that I have decided to simply build each machine from the ground up. Packages take care of the majority of the work, but the final configuration will require tons of hands on, which is why automation is important here.

–PEACE–

Yep. This works for me in my startup script to uncheck the “Nap” checkbox in the Processor pane:


tell process "System Preferences"
		if value of checkbox 1 of window "Processor" is 1 then click checkbox 1 of window "Processor"
end tell