How to enable/disable grayscale mode in Accessibility via Terminal/App? I'm wondering what would be the process of enabling/disabling the grayscale mode in the Accessibility panel in System Preferences?

I would like to run a simple script, either by clicking on an app in the Dock or by a Terminal command, and have it switch from grayscale to regular mode.

Any ideas?
This requires developer tools to compile an objective C program. The program is based on this Stackoverflow answer.

Create a file called grayscale.c with the following contents:

// clang -g -O2 -std=c11 -Wall -framework ApplicationServices
// https://stackoverflow.com/questions/14163788/how-does-on-screen-color-inversion-work-in-os-x
#include &lt;stdio.h&gt;
#include &lt;ApplicationServices/ApplicationServices.h&gt;

CG_EXTERN bool CGDisplayUsesForceToGray(void);
CG_EXTERN void CGDisplayForceToGray(bool forceToGray);

int
main(int argc, char** argv)
{
    bool isGrayscale = CGDisplayUsesForceToGray();
    printf("isGrayscale = %d\n", isGrayscale);
    CGDisplayForceToGray(!isGrayscale);
    printf("Grayscale is now: %d\n", CGDisplayUsesForceToGray());

    return 0;
}


Then run the following command to compile it:

clang -g -O2 -std=c11 -Wall -framework ApplicationServices ./grayscale.c -o toggle-grayscale


Now run ./toggle-grayscale This instantly makes the screen grayscale or not across all applications, but doesn't update the setting in System Preferences.

Tested on MacOS High Sierra 10.13.6, clang version Apple LLVM version 10.0.0 (clang-1000.10.44.4).