Apple Script Change Checkbox in System Preferences Desktop and Screen Savers

Discussion in 'Mac Programming' started by pathumx, Sep 8, 2009.

  1. pathumx macrumors member

    Joined:
    May 7, 2008
    #1
    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.
     
  2. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #2
    It's figuring out crap like this which is why I loathe scripting with System Events.

    See if this works:

    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:"
    			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
     
  3. pathumx thread starter macrumors member

    Joined:
    May 7, 2008
    #3
    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?
     
  4. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #4
    Click the "#" icon to get the Code box.

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

    mt
     

Share This Page