How to programmatically invert screen colors on a Mac

How can I write a script to run on a Mac that inverts screen colors?

Like How to programmatically invert screen colors in Linux , but unfortunately xcalib works on Windows and Linux, but not Mac, as far as I can tell.

EDIT: I have a partial solution. I found a way to reset all my settings before and after inverting the screen colors:

$ mkdir before && mkdir after && cd before
$ for d in $(defaults domains | sed 's/,//g'); do defaults read $d > $d; done
$ cd ../after
$ # System Preferences > Universal Access > Display > White on Black
$ for d in $(defaults domains | sed 's/,//g'); do defaults read $d > $d; done
$ diff -r before after
diff -r before/com.apple.CoreGraphics after/com.apple.CoreGraphics
3c3
<     DisplayUseInvertedPolarity = 0;
---
>     DisplayUseInvertedPolarity = 1;
diff -r before/com.apple.universalaccess after/com.apple.universalaccess
5c5
<     whiteOnBlack = 0;
---
>     whiteOnBlack = 1;

So, now I know which settings are responsible for the inversion of the screen. But when I try the obvious

$ defaults write com.apple.universalaccess whiteOnBlack -int 1
$ defaults write com.apple.CoreGraphics DisplayUseInvertedPolarity -int 1

. , - , , ( , , dotfiles, , Finder ), , , .

+5
3

Apple Script :

tell application "System Events"
    key code 28 using {control down, option down, command down}
end tell

Control-Option-Cmd-8 ( 28 - 8). , , ...

+4

, . , , 1 0.

tell application "System Preferences"
    launch
    set current pane to pane "com.apple.preference.universalaccess"
    tell application "System Events"
        return value of checkbox "Invert colors" of window 1 of process "System Preferences"
    end tell
    quit
end
+1
tell application "System Preferences"
  activate
  reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
  tell application "System Events" to tell process "System Preferences"
    click the checkbox "Invert colors" of window "Accessibility"
  end tell
end tell
tell application "System Preferences" to quit
+1

All Articles