PDA

View Full Version : Apple Script Change Checkbox in System Preferences Desktop and Screen Savers




pathumx
Sep 8, 2009, 04:44 PM
I have 2 macs and i'm trying to sync up the desktop backgrounds via iDisk. Unfortunately, the iDisk doesn't mount immediately so OSX goes back to the default background. In leopard just opening up system preferences to the desktop and screen savers pane fixed the problem, but that fix doesn't work in snow leopard.

I had this script in Leopard:
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.desktopscreeneffect"
quit
end tell

If i toggle the "Change Picture" checkbox off and then back on, it solves the problem. so i need a script for this, and i don't know what i'm doing.



mysterytramp
Sep 8, 2009, 08:53 PM
It's figuring out crap like this which is why I loathe scripting with System Events.

See if this works:

tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.desktopscreeneffect"
end tell

tell application "System Events"
tell process "System Preferences"
tell window "Desktop & Screen Saver"
tell tab group 1
click checkbox "Change picture:"
end tell
end tell
end tell
end tell

And anyone who can polish this code up, feel free to point out where I went wrong. I fiddled with this thing for 20 minutes before I figured out "click button" wasn't good enough. Ugh.

mt

pathumx
Sep 8, 2009, 11:16 PM
almost perfect.

i don't know how to do that nifty code box thing you did in your post, but here is the final code.

tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.desktopscreeneffect"
end tell

tell application "System Events"
tell process "System Preferences"
tell window "Desktop & Screen Saver"
tell tab group 1
click checkbox "Change picture:"
click checkbox "Change picture:"
end tell
end tell
end tell
end tell

tell application "System Preferences"
quit
end tell

i needed to uncheck and then re check it. but that was an easy fix. and then i added a quit at the end.

Thank you for the help! I need to learn how to do this. any good places to learn?

mysterytramp
Sep 9, 2009, 04:56 AM
almost perfect.

i don't know how to do that nifty code box thing you did in your post ...

Click the "#" icon to get the Code box.

any good places to learn?

Here. Macscripter.net. Apple has a listserv on AppleScript. Google. Trial and error. (In my case, more error than trial.)

mt