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.

Programmatically Toggle Colour Filters with AppleScript (osascript assistive access ERR: -25211)

Mac M1 2020. Monterey 12.2.1. ZSH.

I am trying to (title) from a terminal script.

I strongly prefer this method to others.


My error code running `osascript dd.scpt`


dd.scpt:654:718: execution error: System Events got an error: osascript is not allowed assistive access. (-25211)


  • given AEServer and Terminal permissions in Security & Privacy > Accessibility to no avail.
  • unable to find or add osascript permissions here.
  • asked chatGPT multiple times & ways -- unhelpful/fake syntax suggestions for AppleScript
  • looked for similar problems but can't find a solution relevant that works


This code gets to Accessibility > Display > Colour Filters and then throws the error. Changing to British spelling seems to make no difference:

tell application "System Preferences"
	launch
		reveal anchor "Seeing_ColorFilters" of pane "Accessibility"
end tell

tell application "System Events"
	tell application process "System Preferences"
		set frontmost to true
		delay 1
			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
	end tell
end tell
-- tell application "System Preferences" to if it is running then quit

MacBook Air 13″, macOS 12.2

Posted on May 25, 2023 11:08 AM

Reply
Question marked as Top-ranking reply

Posted on May 25, 2023 5:52 PM

The following will toggle grayscale on and off on macOS 12.6.6 (where it was tested), but will not work on Ventura owing to the redesign of its Settings panel. I am looking into that over the weekend…


use framework "Foundation"
use framework "AppKit"
use scripting additions

property ca : current application
property prefpane : "x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_ColorFilters"

(ca's NSWorkspace's sharedWorkspace)'s openURL:(ca's NSURL's URLWithString:prefpane)

tell application "System Events"
	tell application process "System Preferences"
		set frontmost to true
		tell window "Accessibility"
			delay 1
			click first checkbox of tab group 1 of group 1
		end tell
	end tell
end tell

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


The caveat with all of these GUI scripting solutions is Apple has a penchant for changing the design and layout of the Preference panel and GUI scripts break with regularity.

Similar questions

4 replies
Question marked as Top-ranking reply

May 25, 2023 5:52 PM in response to cal147

The following will toggle grayscale on and off on macOS 12.6.6 (where it was tested), but will not work on Ventura owing to the redesign of its Settings panel. I am looking into that over the weekend…


use framework "Foundation"
use framework "AppKit"
use scripting additions

property ca : current application
property prefpane : "x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_ColorFilters"

(ca's NSWorkspace's sharedWorkspace)'s openURL:(ca's NSURL's URLWithString:prefpane)

tell application "System Events"
	tell application process "System Preferences"
		set frontmost to true
		tell window "Accessibility"
			delay 1
			click first checkbox of tab group 1 of group 1
		end tell
	end tell
end tell

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


The caveat with all of these GUI scripting solutions is Apple has a penchant for changing the design and layout of the Preference panel and GUI scripts break with regularity.

May 26, 2023 6:44 AM in response to cal147

And this is for Ventura (tested on 13.4) to toggle grayscale:


(*
	toggleGray.applescript
	
	For Ventura 13.* and may or may not work on macOS 14 and later.
	Reference: https://stackoverflow.com/questions/75152094/applescript-ventura-toggle-accessibility-grayscale-on-off
	
	Tested: macOS Ventura 13.4
	VikingOSX, 2023-05-26, Apple Support Communities, No warranties of any kind.
*)

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

current application's NSWorkspace's sharedWorkspace()'s openURL:(current application's NSURL's URLWithString:"x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_Display")
tell application "System Events" to tell application process "System Settings"
	repeat until exists window "Display"
	end repeat
	click checkbox 1 of group 4 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Display"
end tell

tell application "System Settings" to if it is running then quit
return


Programmatically Toggle Colour Filters with AppleScript (osascript assistive access ERR: -25211)

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