Wondering if anyone know a way to navigate through preference window without making it to the front window or kept in the background.
What I’m trying to achieve is to toggle transparency in the Accessibility setting using apple script. I have the following AppleScript for macOS 12.6
tell application "System Preferences"
if not running then
run
end if
activate
if name of its front window is not "Accessibility" then
reveal pane id "com.apple.preference.universalaccess"
tell pane id "com.apple.preference.universalaccess"
reveal anchor "Seeing_Display"
end tell
end if
end tell
tell application "System Events"
tell application process "System Preferences"
repeat while (get name of window 1) ≠ "Accessibility"
delay 0.1
end repeat
tell window "Accessibility"
tell scroll area 1
tell table 1
set displayPrefs to UI element 1 of rows where its name is "Display"
repeat with i in displayPrefs
if contents of i ≠ missing value then
set displayPrefs to contents of i
end if
end repeat
try
displayPrefs / 0
on error displayPrefRowNum
set AppleScript's text item delimiters to {"«class crow» ", " of «class tabB»"}
set displayPrefRowNum to (text item 2 of displayPrefRowNum) as integer
end try
set displayPrefRow to row displayPrefRowNum
select displayPrefRow
end tell
end tell
tell its tab group 1 of group 1
tell checkbox "Reduce transparency"
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
I have a working Accessibility Transparency Toggle, unfortunately it takes a bit of time 5+ sec.
Anyway to reduce the time?
AppleScript
-------------------------------------------------------------------------------------------
# Author : Jack
# Created : 2023/01/25
# Modified : 2023/03/29
# System : macOS 13.3
# Purpose : Toggle Transparency in System Accessibility Settings
# Url : https://forum.keyboardmaestro.com/t/reduce-transparency/30676/3
# https://www.macscripter.net/t/accessibilitv-applescript/74107/7
-------------------------------------------------------------------------------------------
use AppleScript version "2.5" -- Yosemite (10.10) or later
use scripting additions
if (system version of (system info)) ≤ "12 -- macOS Monterey" then
tell application "System Settings"
if not running then
run
end if
activate
if name of its front window is not "Accessibility" then
reveal pane id "com.apple.preference.universalaccess"
tell pane id "com.apple.preference.universalaccess"
reveal anchor "Seeing_Display"
end tell
end if
end tell
tell application "System Events"
tell application process "System Preferences"
repeat while (get name of window 1) ≠ "Accessibility"
delay 0.1
end repeat
tell window "Accessibility"
tell scroll area 1
tell table 1
set displayPrefs to UI element 1 of rows where its name is "Display"
repeat with i in displayPrefs
if contents of i ≠ missing value then
set displayPrefs to contents of i
end if
end repeat
try
displayPrefs / 0
on error displayPrefRowNum
set AppleScript's text item delimiters to {"«class crow» ", " of «class tabB»"}
set displayPrefRowNum to (text item 2 of displayPrefRowNum) as integer
end try
set displayPrefRow to row displayPrefRowNum
select displayPrefRow
end tell
end tell
tell its tab group 1 of group 1
tell checkbox "Reduce transparency"
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
tell application "System Settings"
if running then
quit
end if
end tell
else
-- macOS Ventura
tell application "System Settings"
if not running then
run
end if
activate
reveal anchor "display" of pane id "com.apple.Accessibility-Settings.extension"
end tell
tell application "System Events"
tell application process "System Settings"
delay 1
tell group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
delay 0.5
tell checkbox "Reduce transparency"
perform action "AXPress"
end tell
end tell
end tell
end tell
tell application "System Settings" to quit
end if
To reveal anchor “Seeing_Display” you can do simply this:
tell application "System Settings"
reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
activate
end tell
No need checking if app is running and on the front. The same approach you can to reveal anchor “display” in other OS.
Wait for window you can simpler as well:
repeat until window "Accessibility" exists
delay 0.1
end repeat
Following:
tell its tab group 1 of group 1
tell checkbox "Reduce transparency"
perform action "AXPress"
end tell
end tell
is the same with
click checkbox "Reduce transparency" of tab group 1 of group 1
Following (written for Ventura):
tell checkbox "Reduce transparency"
perform action "AXPress"
end tell
is same with
click checkbox "Reduce transparency"
First, make your script as concise as possible. Remove the excess, and then users will be more willing to help in the future. Also, you have a GUI here - a script for 2 versions. Splitting into 2 handlers and calling them would make the script more debug friendly.
I am on Catalina, so you need help from other users.