Applescript Select Checkbox Enable Access for accessibility devices - user-interface

I am trying to automatically select the checkbox that will enable access for accessibility devices.
Below is my code which is opening the correct settings window. However, it is not setting the checkbox.
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
end tell
tell application "System Events"
set theCheckbox to checkbox "Enable access for assistive devices"
tell theCheckbox
if not (its value as boolean) then click theCheckbox
end tell
end tell

you just need to set it to enabled
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
end tell
tell application "System Events" to set UI elements enabled to true

Related

Applescript Mojave Toggle Accessibility Grayscale On/Off

I have a script I run periodically to toggle grayscale on/off with Applescript. It runs fine on High Sierra but throw an exception when I use it was Mojave.
tell application "System Preferences"
reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences"
delay 0.5 # Needed or else script fails
set theCheckbox to checkbox "Use grayscale" of window "Accessibility"
tell theCheckbox
# If the checkbox is not checked, check it to turn grayscale on
if not (its value as boolean) then
set checked to true
click theCheckbox
else # else turn grayscale off
set checked to false
click theCheckbox
end if
end tell
end tell
tell application "System Preferences"
quit
end tell
The exception is:
System Events got an error: Can’t get checkbox "Use grayscale" of window "Accessibility" of process "System Preferences". (-1728)
Does Mojave still support Applescript/Would anyone know how to fix this?
As of Catalina, updated to:
# quit system preferences if running
if running of application "System Preferences" then
try
tell application "System Preferences" to quit
on error
do shell script "killall 'System Preferences'"
end try
end if
# wait for system preferences to quit
with timeout of 10 seconds
repeat while running of application "System Preferences" is true
delay 0.01
end repeat
end timeout
# switch to correct anchor
tell application "System Preferences" to reveal anchor "Seeing_ColorFilters" of pane "Accessibility"
#tell application "System Preferences" to activate
#get the name of every anchor of pane "Accessibility" of application "System Preferences"
tell application "System Events" to tell process "System Preferences" to tell window "Accessibility"
#return UI elements of tab group 1 of group 1
with timeout of 10 seconds
repeat until exists checkbox "Enable Color Filters" of tab group 1 of group 1
delay 0.01
end repeat
end timeout
click the checkbox "Enable Color Filters" of tab group 1 of group 1
end tell
tell application "System Preferences" to quit
This works for me Using OS Mojave
tell application "System Preferences"
reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences"
repeat while not (exists of checkbox "Use grayscale" of group 1 of window "Accessibility")
delay 0.1
end repeat
set theCheckbox to checkbox "Use grayscale" of group 1 of window "Accessibility"
tell theCheckbox
# If the checkbox is not checked, check it to turn grayscale on
if not (its value as boolean) then
set checked to true
click theCheckbox
else # else turn grayscale off
set checked to false
click theCheckbox
end if
end tell
end tell
tell application "System Preferences"
quit
end tell

How to click a checkbox of a drop-down tab in System Preferences

I'm trying to make an AppleScript to change an option in System Preferences. The checkbox is revealed by clicking "Mouse Options..." in the "Mouse and Trackpad" menu of the "Accessibility" pane. The script I have written so far is able to navigate through System Preferences so that the desired checkbox is visible to be clicked. However, I can't find a way to click the checkbox, seemingly because the checkbox is within a sort of 'drop down tab' on the window. None of the tutorials I have found online deal with this specific issue.
My code so far-
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.universalaccess"
get the name of every anchor of pane id "com.apple.preference.universalaccess"
reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
tell application "System Events" to tell process "System Preferences"
click button 5 of window "Accessibility"
end tell
end tell
The desired checkbox is "Scrolling". I expected that the following code would work, but it does not- it clicks checkboxes in the background, not the one in the tab.
tell application "System Events" to tell process "System Preferences"
click checkbox 1 of window "Accessibility"
end tell
This is my first time using AppleScript, I should mention. Any help would be much appreciated.
The 'drop down tab' is called a sheet:
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.universalaccess"
reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
tell application "System Events" to tell process "System Preferences"
click button 5 of window 1
click checkbox 1 of sheet 1 of window 1
end tell
end tell

How to set checkbox in Mission Control?

I'm trying to set checkbox in Mission Control pane in System Preferences. So far I'm able to open MC but I have no idea how to click on checkbox. I tried everything I found on Internet but with no luck...
How can I do it?
tell application "System Preferences" activate set current pane to
pane "com.apple.preference.expose" end tell
This will click the first checkbox of the pane only if it is currently not checked:
tell application "System Preferences"
set current pane to pane "com.apple.preference.expose"
activate
end tell
tell application "System Events"
tell process "System Preferences"
set firstCheckbox to checkbox 1 of group 2 of window 1
set checked to value of firstCheckbox as boolean
if (not checked) then
click firstCheckbox
end if
end tell
end tell

Verify a checkbox before clicking with Applescript

I'm facing an issue with one of my applescript.
I'm trying to create an applescript that check/uncheck the checkbox that call the password after the mac wake up or the screensaver stop in the mac security pannel.
I'm using this with proximity.app, with the idea that when i'm back home and my phone is in range, proximity.app remove the password, but when i'm out of range, it put the password back.
Well... I'm forced to do it using UI scripting, because of the new security policy in Mountain Lion.
So there is the code when out of range :
tell application "System Preferences"
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
tell process "System Preferences"
tell first window
tell first tab group
click radio button 1
if not 1 then click checkbox 1
click menu item 6 of menu of pop up button 1
end tell
end tell
end tell
end tell
quit
end tell
and when in range :
tell application "System Preferences"
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
tell process "System Preferences"
tell first window
tell first tab group
click radio button 1
click checkbox 1
end tell
end tell
end tell
end tell
quit
end tell
What i want to improve, is a way to first verify if the box is check or uncheck before checking or unchecking it.
Thanks for your help.
Just check the value of the checkbox.
0 = Uncheck, 1 = check
tell application "System Preferences" to ¬
reveal anchor "Advanced" of pane id "com.apple.preference.security"
tell application "System Events"
tell first tab group of first window of process "System Preferences"
tell checkbox 1 to if value is 0 then click -- checkbox was not checked.
end tell
end tell
quit application "System Preferences"

Dropdown in Monitor System Preferences

tell application "System Events"
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.displays"
set theWindows to windows
set win2 to item 2 of theWindows
tell win2
set index to 1
set visible to false
set visible to true
end tell
set value of combo box 1 to "90°"
end tell
end tell
I'm trying to change the Rotation of the External Screen via Applescript, but I do
not find out how to access this dropdown menu. Google seems to give me a lot about combo box and pop menu, but under Lion at least all this stuff doesn't work.
This worked for me on 10.8.
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences"
tell pop up button 1 of tab group 1 of window 1
click
click menu item 3 of menu 1
end tell
end tell

Resources