Scripting Universal Access Preference Pane

Thanks in very great part to this BBS and to Apple’s “UIElementInspector” and to the commercial “UI Browser”, I have developed a script to clear the Recent Items menu. Before I present my listing, I’d like to present some questions I need serious help on:

  1. is there any way at all to turn on “Enable access for assistive devices” without it being turned on? Clearly, one cannot check this UNchecked box without UI scripting being turned on. Literally, a Catch 22. As you have seen elsewhere and below, I use the typical display dialog approach, a far cry from the automatic nature of Scripting. For example, how can one utilize Applescript to open the appropriate .plist file, modify it and then re-save? I cannot seem to find such a .plist file for the System Preferences application.

  2. only by dumb luck did I note that the name of the button “Universal Access” is really “Universal\nAccess”. But what eludes me is that my script will work in (a), but not (b):

(a)

click button ("Universal
Access") of scroll area 1 of front window -- "\n" between button name

(b)

set buttonName to "Universal" + return + "Access"
click button ("\"" & buttonName & "\"") of scroll area 1 of front window

  1. okay, here’s the entire code, (almost) without comments:
my ClearRecentItemsMenu()

on ClearRecentItemsMenu()
	try	
		tell application "System Events" to set UI_enabled to UI elements enabled

		if UI_enabled is false then
			my ActivateUniversalAccess()
			
			tell me to display dialog ¬
				"Turn on" & return & ¬
				" 'Enable access for assistive devices'" & return & ¬
				"before you continue further" buttons {"Cancel", "Continue"} ¬
				default button {"Continue"} with icon stop giving up after 5
			
			-- look at the value again
			tell application "System Events" to set UI_enabled to UI elements enabled
			
			if UI_enabled is true then
				my ActivateUniversalAccess()
				delay 1
				my doClearRecentItems()
				delay 1
				my DisableAccess()
				delay 1
				
				quit application "System Preferences"
			end if
		else
			my doClearRecentItems()
		end if	
	end try	
end ClearRecentItemsMenu

on ActivateUniversalAccess()
	tell application "System Preferences" to activate
	
	-- this is all that works with "Enable access ..." off
	tell application "System Preferences" to set ¬
		current pane to pane "com.apple.preference.universalaccess"
end ActivateUniversalAccess

on DisableAccess()
	tell application "System Events" to tell process "System Preferences"
		click checkbox "Enable access for assistive devices" of front window
	end tell
end DisableAccess

on doClearRecentItems()
	tell application "System Events"
		click menu item "Clear Menu" of ¬
			menu "Recent Items" of ¬
			menu item "Recent Items" of ¬
			menu "Apple" of ¬
			menu bar item "Apple" of ¬
			menu bar 1 of ¬
			(first process whose frontmost is true)
	end tell
end doClearRecentItems

That’s because “return” is the wrong character. When used in such a context, return will insert a carriage return (ASCII character 13); however, you need a line feed (ASCII character 10, aka “newline”).

Try changing B to this:

set buttonName to "Universal" & ASCII character 10 & "Access"
click button ("\"" & buttonName & "\"") of scroll area 1 of front window