MacOS – How to toggle with grayscale in Yosemite

accessibilitymacosshortcut

I prefer greyscale over inverting color when working in low light plus in general as its less strain on the eyes. But its too many clicks to toggle the settings.
I am aware that to invert display color the shortcut is Cmd+Alt+Ctrl+8. And open Accessibility options with Cmd+Alt+F5, but there is no grayscale in the options.
Right now, I open Accessibility via spotlight, then choose display & toggle the check box. I am wondering of there is any shortcut key for that? If not, is it possible to make a keyboard shortcut.

Best Answer

The following example AppleScript code will toggle the state of the "Use grayscale" checkbox in Accessibility under System Preferences in OS X Yosemite (tested under 10.10.4) regardless of what was last selected under Accessibility as it tells System Preferences to open directly to the location of the "Use grayscale" checkbox and toggle its state.

tell application "System Preferences"
    reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
    tell application "System Events" to tell front window of application process "System Preferences"
        with timeout of 5 seconds
            repeat until (exists checkbox "Use grayscale")
                delay 0.1
            end repeat
            click checkbox "Use grayscale"
        end timeout
    end tell
    quit
end tell

The next issue is how you want to execute it. The problem surrounding setting it as a Service through Automator to use a Keyboard shortcut without the use of a third party utility is every application that receives the shortcut key combo will need to have permission to do so and that becomes a pain unless you only choose e.g. Finder instead of all applications. So without a third party utility I'd either save it as a script in the Users Script folder and then access it from the Script menu in the Apple menu bar or as an application.

The settings for the Script menu in the Apple menu bar are in the Script Editors Preferences. Then it's just two mouse clicks anytime you want to toggle the state of the "Use grayscale" checkbox. One to click the Scripts menu and another to click the script name.

As an application it can be placed in the Dock and then it's a single mouse click anytime you want to toggle the state of the "Use grayscale" checkbox.

In either of these two cases you'll have to give permission under Accessibility on the Privacy tab of Security & Privacy in System Preferences in order to run it successfully.


As a side note, if you use a program like FastScripts, you only need to use the example AppleScript code as a .scpt saved in Script Editor, not create an Automator service using the mentioned workaround in the comment and can assigned the keyboard shortcut in the Preferences for FastScripts.

Note that I am not affiliated with the developer of FastScripts, just a satisfied user.