Re: Programatically Uncheck "Change Picture" In Desktop Settings?
Re: Programatically Uncheck "Change Picture" In Desktop Settings?
- Subject: Re: Programatically Uncheck "Change Picture" In Desktop Settings?
- From: Chunk 1978 <email@hidden>
- Date: Fri, 13 Feb 2009 21:29:13 -0500
thanks a million ken!... this helps me on so many levels :)
On Fri, Feb 13, 2009 at 9:02 PM, Ken Thomases <email@hidden> wrote:
> On Feb 13, 2009, at 6:25 PM, Chunk 1978 wrote:
>
>> when running my apple script i get this error:
>>
>> -=-=-=-
>> System Events got an error: Access for assistive devices is disabled.
>> -=-=-=-
>>
>> so if i goto system prefs and check "Enable access for assistive
>> devices", then running the script i get this error:
>>
>> -=-=-=-
>> System Events got an error: Can't get application process "System
>> Preferences".
>> -=-=-=-
>>
>> here's my script:
>>
>> -=-=-=-
>> tell application "System Events"
>> tell application process "System Preferences"
>> if value of checkbox "Change picture:" of group 1 of tab
>> group 1 of
>> window "Desktop & Screen Saver" is 1 then
>> click checkbox "Change picture:" of group 1 of tab
>> group 1 of
>> window "Desktop & Screen Saver"
>> end if
>> end tell
>> end tell
>> -=-=-=-
>
> You're trying to do things the indirect, and thus hard, way. First, you're
> trying to do GUI scripting by poking directly at controls (checkboxes,
> groups, tabs, windows, etc.). That's inherently fragile and requires that
> access for assistive devices be enabled (as you've seen). By the way,
> wrapping a tell block that's addressing System Preferences inside of a tell
> block to System Events doesn't really help. The reason I told you to script
> System Events was that you shouldn't be scripting System Preferences.
>
> Using Script Editor's Library, open the dictionary for System Events. Look
> at the Desktop Suite. There's a class "desktop" which has a "picture
> rotation" property (as well as others you may find useful). From the
> containment hierarchy view, we see that the application object contains
> "desktops" and has a "current desktop" property of this class. So:
>
> tell application "System Events"
> set the picture rotation of current desktop to 0
> end tell
>
> Or, because there can be multiple desktops:
>
> tell application "System Events"
> repeat with theDesktop in desktops
> set picture rotation of theDesktop to 0
> end repeat
> end tell
>
> Since your original purpose was to set the desktop background picture, you
> may wish to 'set picture of theDesktop to POSIX file "/path/to/my/picture"'
> in the script, too. (You may specify the file in some other way, of
> course.)
>
> Regards,
> Ken
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden