You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Toggle Grayscale keyboard shortcut problem (Catalina)

I'm hoping someone will have some insight or advice on updating a script to toggle Grayscale in macOS Catalina. There was a previous post addressing the script on High Sierra and Mojave, but since the Accessibility menu has been updated in Catalina, it no longer works.


Thank you in advance for any help you can offer!

Posted on Oct 12, 2019 12:00 PM

Reply
Question marked as Top-ranking reply

Posted on Nov 19, 2019 7:37 AM

I have upgraded my set_grayscale.applescript so that it now works on High Sierra, Mojave, and Catalina. Thanks to SteverX1 for providing the Catalina related GUI scripting information.


-- 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.1
-- 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

11 replies
Question marked as Top-ranking reply

Nov 19, 2019 7:37 AM in response to bradleytown

I have upgraded my set_grayscale.applescript so that it now works on High Sierra, Mojave, and Catalina. Thanks to SteverX1 for providing the Catalina related GUI scripting information.


-- 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.1
-- 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


Oct 12, 2019 1:39 PM in response to bradleytown

Well this should be handwriting on the wall about the fragility of GUI scripting and its failure as soon as Apple modifies the underlying panel elements. I wrote that script and it works correctly on High Sierra and Mojave. I probably will not even bother to upgrade to Catalina until the .1 or .2 updates are out, so no fixes coming from me on this script.

Oct 14, 2019 12:14 PM in response to VikingOSX

Thank you so much for the work you did on the original scripts! They've been very useful for myself and likely others. I was hoping you might still have some insight on the syntax I would use for selecting the menus within menus (Display, Cursor and Color Filters tabs)? I've been diving into AppleScript to try and solve this myself, but I haven't been able to find the right syntax for that particular step.


Thank you!

Nov 18, 2019 7:02 PM in response to bradleytown

I found this script on StackOverflow (https://stackoverflow.com/questions/52583402/applescript-mojave-toggle-accessibility-grayscale-on-off) and it works for me:


# 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


Nov 22, 2019 6:44 AM in response to LHLancelot

I copied the content of the Nov 19 posted script above — into Script Editor on Catalina 10.15.1. Unsurprisingly, I was able to set grayscale, or remove it in subsequent runs of the script. Exactly how it tested before I posted it.


I can watch it open the colored filters panel and check the Enable Color Filters box, as it would have to do for correct operation.

Toggle Grayscale keyboard shortcut problem (Catalina)

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