On Mojave I don’t have the permissions anymore and so I’ve to add sudo or do shell script with administrator privileges.
The problem is, that unlike using the checkbox in the system preferences, running apps seem not to be informed about this changed preference. Is there a way to tell it to them so they change their appearance?
I don’t like your chances, but you could try this:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
set theNotif to current application's NSNotification's notificationWithName:(current application's NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification) object:(missing value)
current application's NSDistributedNotificationCenter's defaultCenter()'s postNotification:theNotif
As there seems to be no other way, have you simply considered scripting System Preferences and System Events to do this ? I normally abhor UI scripting, but System Preferences is the one exception for which it lends itself very cleanly to.
as I hate UI scripting I tried other stuff. Now I’ve a solution I can live with. It uses the keyboard shortcut for inverting the screen colors. This will refresh all windows with the current contrast mode setting.
if (do shell script "defaults read com.apple.universalaccess increaseContrast; true") is "1" then
do shell script "defaults write com.apple.universalaccess increaseContrast -bool false"
else
do shell script "defaults write com.apple.universalaccess increaseContrast -bool true"
end if
tell application "System Events"
-- Toggle Invert Colors on German keyboard
keystroke "{" using {command down, option down, control down}
keystroke "{" using {command down, option down, control down}
-- Toggle Invert Colors on international keyboard
keystroke 28 using {command down, option down, control down}
keystroke 28 using {command down, option down, control down}
end tell
To let the script allow changing the prefs via shell script, you have to give the script full disc access in Mojave and later.