Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
System Prefs > Desktop & Screen Saver > Desktop > Change picture: (checkbox).

so i'm trying to make a script that says if this checkbox is checked, than to uncheck it... simple right? not really... i kinda suck at applescript...

this is what i have so far...

Code:
tell application "System Events"
	tell application process "System Preferences"
		if checked of checkbox "Change picture:" of group 1 of tab group 1 of window "Desktop & Screen Saver" is true then
			set checkbox "Change picture:" of group 1 of tab group 1 of window "Desktop & Screen Saver" to false
		end if
	end tell
end tell

and unfortunately it doesn't work. i receive this message from the compiler:

"System Events got an error: Can't make checked of checkbox "Change picture:" of group 1 of tab group 1 of window "Desktop & Screen saver" of application process "System Preferences into type reference."

any thoughts?
 
Change the script to this:

Code:
		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

There's a utility at: /Developer/Applications/Utilities/Accessibility Tools/

called Accessibility Inspector.app

It shows the actions and proper value get/set for UI scripting.
 
Code:
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

i see how your code makes sense, but it gives this error:

System Events got an error: Access for assistive devices is disabled.

hummmm... :confused:
 
oh i see what that error means now... i have to check "enable access for assistive devices" under universal access in system prefs...

but since it seems i have to check "enable access for assistive devices" first, i may not be able to do what i want. essentially, in my application i want to include this apple script in an IBAction... but i guess it wouldn't work unless the user's "enable access for assistive devices" is checked? maybe is there a way to allow my app to check that checkbox first? hah...

round and round we go...
 
was that a dumb question? i really have no idea... :confused:

if i publish an applescript online, or a cocoa app with applescript embedded in an IBAction that toggels a checkbox on the user's system (sys prefs > desktop & screensaver > desktop > change picture), and a user downloads the script/app expecting it to work, will it not work for them if their own "enable access for assistive devices" is not checked in sys preferences > universal access?

if someone could just respond YES or NO that would be great... :eek:
 
Yes, that is right. You can check for it programmatically though via something like this:
Code:
tell application "System Events"
    if UI elements enabled then
        -- continue
    end if
end tell
 
Yes, that is right. You can check for it programmatically though via something like this:
Code:
tell application "System Events"
    if UI elements enabled then
        -- continue
    end if
end tell

sorry, are you saying that it's possible to check to see if the "enable access for assistive devices" is checked on the users computer first, if it's not then check it, and THEN launch the applescript to check the "change picture"?

ouff! so confusing...
 
Changing UI Settings

"maybe is there a way to allow my app to check that checkbox first?"

yeah, there is a way. No idea if you're still interested, but here's my little dirty hack to get assistive Devices enabled in System Preferences without GUI-scriptings [snip]:

set PWD to "YourPasswordHere"

do shell script "touch /private/var/db/.AccessibilityAPIEnabled" password PWD with administrator privileges
do shell script "chown 0 /private/var/db/.AccessibilityAPIEnabled" password PWD with administrator privileges
do shell script "chgrp 0 /private/var/db/.AccessibilityAPIEnabled" password PWD with administrator privileges
do shell script "chmod 0444 /private/var/db/.AccessibilityAPIEnabled" password PWD with administrator privileges

The code is not formatted right, but I guess you'll get the idea.

In step 1 we create an invisible file named ".AccessibilityAPIEnabled" in a system folder, then in step 2 - 4 we change its privileges as needed for our purpose.
Please note that this is exact the way Apple handles the storage of this setting, so it's less a hack than sort of reverse engineering I've done years before ...

Furthermore: You'll need an admin password to perform this.
Enter it once in "YourPasswordHere" or read it out by a plist you have stored before.

Warning: Use correct privs for such a plist! If the admin password is stored as clear text in a plist it'll be readable by every user.
A massive security risk imo.

Hope that helps, cheers.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.