Skip to main content
2 of 4
deleted 4 characters in body
user3439894
  • 59.8k
  • 10
  • 112
  • 135

This 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"
    activate
    reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
    tell application "System Events" to tell process "System Preferences"
        click the checkbox "Use grayscale" of window "Accessibility"
    end tell
end tell
tell application "System Preferences" to quit

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 Script menu in the Apple menu bar is 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.

user3439894
  • 59.8k
  • 10
  • 112
  • 135