Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 20, 2008, 12:03 PM   #1
Darkroom
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
Applescript Change Checkbox in System Preferences

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?
Darkroom is offline   0 Reply With Quote
Old Sep 20, 2008, 12:20 PM   #2
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
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.
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Sep 20, 2008, 12:24 PM   #3
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
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...
Darkroom is offline   0 Reply With Quote
Old Sep 20, 2008, 12:33 PM   #4
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
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...

Last edited by Darkroom; Sep 20, 2008 at 12:45 PM.
Darkroom is offline   0 Reply With Quote
Old Sep 21, 2008, 11:50 AM   #5
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
?

Last edited by Darkroom; Sep 24, 2008 at 07:44 PM.
Darkroom is offline   0 Reply With Quote
Old Sep 24, 2008, 07:45 PM   #6
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
was that a dumb question? i really have no idea...

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...
Darkroom is offline   0 Reply With Quote
Old Sep 24, 2008, 09:18 PM   #7
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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
kainjow is offline   0 Reply With Quote
Old Sep 24, 2008, 09:24 PM   #8
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
Quote:
Originally Posted by kainjow View Post
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...
Darkroom is offline   0 Reply With Quote
Old Sep 25, 2008, 12:49 AM   #9
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
You can't (AFAIK) automatically enable it if it's disabled.
kainjow is offline   0 Reply With Quote
Old Sep 25, 2008, 01:15 AM   #10
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
ok thanks kainjow
Darkroom is offline   0 Reply With Quote
Old Sep 12, 2009, 09:42 AM   #11
cocoascripter
macrumors newbie
 
Join Date: Sep 2009
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.
cocoascripter is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
System preferences cool11 OS X Mavericks (10.9) 1 Apr 17, 2014 01:11 PM
Hide OSX System Preferences in Applescript for toggling ignore trackpad in Mavericks? mactp Mac Programming 9 Mar 16, 2014 07:03 PM
Resolved: System Preferences is not registering setting change Animalk OS X Mavericks (10.9) 9 Nov 30, 2013 08:01 PM
System preferences jennytisme Mac OS X 10.7 Lion 1 Mar 15, 2013 02:13 PM
System preferences verithingeoff OS X 10.8 Mountain Lion 0 Feb 3, 2013 06:19 PM

Forum Jump

All times are GMT -5. The time now is 12:17 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC