• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Programatically Uncheck "Change Picture" In Desktop Settings?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programatically Uncheck "Change Picture" In Desktop Settings?


  • Subject: Re: Programatically Uncheck "Change Picture" In Desktop Settings?
  • From: Ken Thomases <email@hidden>
  • Date: Fri, 13 Feb 2009 20:02:29 -0600

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


  • Follow-Ups:
    • Re: Programatically Uncheck "Change Picture" In Desktop Settings?
      • From: Chunk 1978 <email@hidden>
References: 
 >Programatically Uncheck "Change Picture" In Desktop Settings? (From: Chunk 1978 <email@hidden>)
 >Re: Programatically Uncheck "Change Picture" In Desktop Settings? (From: Ken Thomases <email@hidden>)
 >Re: Programatically Uncheck "Change Picture" In Desktop Settings? (From: Chunk 1978 <email@hidden>)

  • Prev by Date: Re: Cursor color in NSTextField?
  • Next by Date: Line spacing in NSTextView
  • Previous by thread: Re: Programatically Uncheck "Change Picture" In Desktop Settings?
  • Next by thread: Re: Programatically Uncheck "Change Picture" In Desktop Settings?
  • Index(es):
    • Date
    • Thread