Toggling Accessibility's "Enable Color Filters" with AppleScript

Hi all,


I'm trying, with AppleScript to create a keyboard shortcut that would toggle the "Enable Color Filters" setting in Accessibility in System Preferences. I used to use a script that was something like this one:


tell application "System Preferences"

launch

reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"

end tell

tell application "System Events" to tell process "System Preferences"

delay 1

click checkbox "Enable Color Filters" of window "Accessibility"

end tell

tell application "System Preferences" to if it is running then quit

return


From here:

https://discussions.apple.com/thread/8247628


But updating my system to Catalina 10.15, the arrangement of the System Preferences window changed. As I understand it, I now need to first go to Accessibility, then to "Display," and then to the "Color Filters" tab, and then toggle it.


How might I go about doing this?


Any help would be really appreciated!

MacBook Pro 13", macOS 10.15

Posted on Jan 6, 2020 12:13 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 10, 2020 2:16 AM

The following GUI AppleScript toggles grayscale with each run, and has been tested on Catalina 10.15.2, Mojave 10.14.6, and High Sierra 10.13.6.


-- set_grayscale.applescript
-- alternates between grayscale and normal display with each run.
-- Tested on High Sierra (10.13.6), Mojave (10.14.6), and Catalina 10.15.2
-- Revision: 11/19/2019, Upgrade script for Catalina
-- VikingOSX, 12/30/2018, Apple Support Communities, No warranty at all

set os_ver to do shell script "sw_vers -productVersion | cut -d '.' -f1-2"

tell application "System Preferences"
	launch
	if os_ver < "10.15" then
		reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
	else
		reveal anchor "Seeing_ColorFilters" of pane "Accessibility"
	end if
end tell

tell application "System Events"
	tell application process "System Preferences"
		set frontmost to true
		delay 1
		if os_ver = "10.15" then
			tell window "Accessibility"
				repeat until exists checkbox "Enable Color Filters" of tab group 1 of group 1
					delay 0.01
				end repeat
				click first checkbox of tab group 1 of group 1
			end tell
		else if os_ver = "10.14" then
			tell group 1 of window "Accessibility"
				click checkbox "Use grayscale"
			end tell
		else if os_ver < "10.14" then
			tell window "Accessibility"
				click checkbox "Use grayscale"
			end tell
		end if
	end tell
end tell
tell application "System Preferences" to if it is running then quit


Similar questions

1 reply
Question marked as Top-ranking reply

Jan 10, 2020 2:16 AM in response to tangowhiskyman

The following GUI AppleScript toggles grayscale with each run, and has been tested on Catalina 10.15.2, Mojave 10.14.6, and High Sierra 10.13.6.


-- set_grayscale.applescript
-- alternates between grayscale and normal display with each run.
-- Tested on High Sierra (10.13.6), Mojave (10.14.6), and Catalina 10.15.2
-- Revision: 11/19/2019, Upgrade script for Catalina
-- VikingOSX, 12/30/2018, Apple Support Communities, No warranty at all

set os_ver to do shell script "sw_vers -productVersion | cut -d '.' -f1-2"

tell application "System Preferences"
	launch
	if os_ver < "10.15" then
		reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
	else
		reveal anchor "Seeing_ColorFilters" of pane "Accessibility"
	end if
end tell

tell application "System Events"
	tell application process "System Preferences"
		set frontmost to true
		delay 1
		if os_ver = "10.15" then
			tell window "Accessibility"
				repeat until exists checkbox "Enable Color Filters" of tab group 1 of group 1
					delay 0.01
				end repeat
				click first checkbox of tab group 1 of group 1
			end tell
		else if os_ver = "10.14" then
			tell group 1 of window "Accessibility"
				click checkbox "Use grayscale"
			end tell
		else if os_ver < "10.14" then
			tell window "Accessibility"
				click checkbox "Use grayscale"
			end tell
		end if
	end tell
end tell
tell application "System Preferences" to if it is running then quit


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Toggling Accessibility's "Enable Color Filters" with AppleScript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.