7

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.

  • 1
    It doesn't look like you can. I took a peek around the keyboard shortcuts area (under Keyboard in System Preferences) and there doesn't seem to be a way to make the screen grayscale via key bind. :( – Florrie Jul 21 '15 at 10:11
2

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.

| improve this answer | |
  • Thanks a lot for the solution. I save it as an application on the dock. Guess its safer to give control that that one app instead of the whole Script editor. Thanks a lot for the answer. – qbektrix Jul 23 '15 at 15:32
  • @qbektrix, Yes, from a security perspective, that is a safer way to go. BTW If you don't like the icon you can change the icon by replacing the "applet.icns" file inside the application bundle or use 3rd party utility to assign it a different icon. If you do it manually .icns file has to have the same name even if renamed from a "different_name.icns" file. Right-click the application bundle and select Show Package Contents then goto Contents/Resources/. You'll probably fave to run killall Finder and killall Dock to get the new .icns file to show or a logout/login cycle should do. – user3439894 Jul 23 '15 at 15:56
  • I managed to hack around the "every app will need permission" problem by saving the greyscale script as an Automator application, and then creating an Automator service that just launches that application. I give the service the keyboard shortcut, and the application gets permission to control my computer. Edit: Just noticed that there's a link in the second answer that recommends doing the same thing! So kudos to them. They also have a 0.5 second delay in their script — I found I needed that too. – ivanreese Jul 30 '16 at 11:37
2

I have found an old Apple Discussion about this and the user who answered the question has posted an AppleScript file that will turn on and off grayscale. I have modified the original code so it would work with OS X Yosemite.

Open "Script Editor" and, in a new document, paste the following:

tell application "System Preferences" to activate
delay 1

tell application "System Events"
tell process "System Preferences"
click the menu item "Accessibility" of the menu "View" of menu bar 1
delay 0.5
click the checkbox "Use grayscale" of window "Accessibility"
end tell
end tell
tell application "System Preferences" to quit

Click the hammer to compile it and then save but where it says "File Format" in the save dialog, choose "Application"

Before running this code make sure that "Display" in Accessibility has been selected like the image below. Once that has been done, you can quit System Preferences.

Make sure that before running this, "Display" is highlighted in Accessibility

On the first run of the app, it will crash and OS X will ask if you want to allow the app to control the computer using accessibility features. Allow access, quit the app and relaunch it.

Sometimes this will not work and will crash with an error message. If this happens, just relaunch it and it will work fine.

EDIT: This may help with making it a keyboard shortcut: Link

| improve this answer | |
  • One issue in particular with your AppleScript is you're assuming that when the Accessibility preferences is opened that it will be on Display however it may not as it will be on whatever was selected last. As an example if it was last on Zoom, it will open to Zoom and it will error out with: "AppleScript Error System Events got an error: Can’t get checkbox "Use grayscale" of window "Accessibility" of process "System Preferences"." – user3439894 Jul 23 '15 at 1:32
  • Thanks @user3439894, I'm not that good with AppleScript – CreeperzEdge Jul 23 '15 at 5:20
  • @CreeperzEdge, thanks a lot for the answer. The link on making keyboard shortcut was really helpful. – qbektrix Jul 23 '15 at 15:36
2

I used the script from @CreeperzEdge answer and it had a bit of delay on my computer. I've slightly changed that script to:

tell application "System Preferences" to reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
tell application "System Preferences"
    activate
    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

Somehow

tell application "System Preferences" to reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"

is faster than

tell application "System Preferences"
    activate
    reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell

I would be curious about others' experience.

| improve this answer | |
1

I found that a 1-second delay was needed to get it to work for me.

tell application "System Preferences"
    activate
    reveal anchor "Seeing_Display" of pane "com.apple.preference.universalaccess"
    delay 1
    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
| improve this answer | |
1

I have built an app to make this process easier. It allows you to toggle the grayscale display from the status bar. It's a wrapper around the AppleScript mentioned in the answers written using PyObjC. I have tested it to work on macOS Mojave.

You can download it from here. The source code is here.

Note: Due to Apple's restrictions, the app needs three kinds of permissions in order to work: a) allow opening an app from an unidentified developer b) allow access to System Events. c) accessibility permissions.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .