Scripting a checkbox

Hi everyone,

I know GUI scripting is typically not suggested due to the rapid changes between OS builds, but I’ve been searching over a week now on how to script the System Preferences “Change picture:” check box within Desktop & Screen Savers. I’ve seen a few scripts here on this site that do just that, but none of them have worked. I thought rewriting the com.apple.desktop.plist was the best bet (and I did score it with moderate success), but evidently you can only change the desktop picture and paths, not any other variants of that preference pane (although change intervals are flagged within the plist’s XML) without crashing that particular tab in System Preferences. I’ve used UIBrowser and UIElementInspector again with moderate success. So I ask you script gurus, please help me out.

This is the best of what I have so far (even if it’s elementary) and please let me know if I can also adjust the change interval to 5 minutes:

tell application "System Preferences"
	set current pane to pane id "com.apple.preference.desktopscreeneffect"
	delay 2
	tell application "System Events"
		tell application "System Preferences" of window 1 of tab group 1 of group 1 of checkbox 1 to set to true
		end tell
	end tell
end tell

PS - Is this completely out of the question?

do shell script "defaults write com.apple.desktop Background '{default = {Change = TimeInterval; ChangePath = "/Library/Desktop Pictures/Plants"; ChangeTime = 300; CollectionString = Plants; ImageFileAlias = <00000000 00cc0003 00000000 bf7350f9 0000482b 00000000 0000ed78 0000ed82 0000bf2e d60d0000 00000920 fffe0000 00000000 0000ffff ffff0001 000c0000 ed780000 ed4a0000 0af1000e 00220010 00500075 00720070 006c0065 00200046 0072006f 006e0064 002e006a 00700067 000f001a 000c004d 00610063 0069006e 0074006f 00730068 00200048 00440012 00304c69 62726172 792f4465 736b746f 70205069 63747572 65732f50 6c616e74 732f5075 72706c65 2046726f 6e642e6a 70670013 00012f00 ffff0000 >; ImageFilePath = "/Library/Desktop Pictures/Plants/Purple Frond.jpg"; Random = 1; TimerPopUpTag = 3; }; }'"
do shell script "killall Dock"

Model: eMac
AppleScript: 2.1.1 (81)
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi

Try This:

tell application "System Preferences"
	activate
	set current pane to pane id "com.apple.preference.desktopscreeneffect"
end tell
tell application "System Events"
	tell application process "System Preferences"
		click checkbox "Change picture:" of group 1 of tab group 1 of window "Desktop & Screen Saver"
	end tell
end tell

drawn a blank with the change every 5 minutes pop up though!! sorry

Pidge, that’s awesome thanks!!! :lol:

I can’t tell you how long I’ve been trying to wrap my head around that. As for adjusting the “Change picture:” rotation I’ve been able to adjust only through a shell command and even that seemingly wipes the plist to once again disable the checkbox (also it only defaults to 30 minutes no matter how many seconds you assign to it) by adding:

do shell script "defaults write com.apple.desktop Background ChangeTime=300"

I will keep on working on this and see what I can come up with. In the meantime I truly appreciate your assistance.

Anthony>>

OK, I figured out how to accurately change the desktop (and in what increments) thanks to both pidge and kai. All I did was add kai’s changetime formula to the script pidge helped me iron out. Thank you both, this is all part of a greater scheme in which I automate tweaking of ByHost preferences when they sometimes don’t carry over after a netinstall.


--desktop script - (Thanks to both kai and pidge!). UI script clicks Sys Pref check box while finding and modifying the "changeTime" path inside the desktop.plist XML.  PS - since paths are used as opposed to visual UI scripting, the "Change picture:" drop down menu will not accurately reflect the interval in which it changes. 

tell application "System Preferences"
	activate
	set current pane to pane id "com.apple.preference.desktopscreeneffect"
end tell
tell application "System Events"
	tell application process "System Preferences"
		click checkbox "Change picture:" of group 1 of tab group 1 of window "Desktop & Screen Saver"
		tell application "System Events" to tell (property list item "ChangeTime" of (property list items where ¬
			name of property list items contains "ChangeTime")) of property list item "Background" of ¬
			property list file ((path to preferences as Unicode text) & "com.apple.desktop.plist") to if exists then
			set v to "300.000000"
			set value to (v div 0.5) - v + 0.01
		end if
	end tell
end tell