AppleScript: Toggle Grayscale On/Off with a Keyboard Shortcut

So OS X 10.11 – El Capitan broke an AppleScript that I had been using to toggle grayscale mode on/off, resulting in a script error:

AppleScript Error

All it took was adding a delay to fix the script (notated as a comment in the script below).

If you are running into errors with a previously used “Toggle Grayscale” AppleScript (or perhaps any AppleScript) in El Capitan, you may want to try adding “delay 1” in the line before the error occurs.

Okay, enough digression.

Fix or Create Script
    1. Open Script Editor.app, located in Applications>Utilities.
    2. Copy and paste the following:
      tell application "System Preferences"
      	activate
      	reveal (pane id "com.apple.preference.universalaccess")
      end tell
      
      tell application "System Events"
      	tell process "System Preferences"
      		tell window "Accessibility"
      			tell table 1 of scroll area 1
      				-- Added "delay 1" to work in 10.11 - El Capitan
      				delay 1
      				select (row 2)
      			end tell
      			click checkbox "Use grayscale"
      		end tell
      	end tell
      end tell
      tell application "System Preferences" to quit
      
    3. Click Compile, then Run to verify it works. Preview:
    4. Save the script file (.scpt).

Assign Script to a Keyboard Shortcut
    1. To map the script to a keyboard shortcut, such as a F key or a multiple key combination, download, install, and run BetterTouchTool (BTT). There’s a free trial version but it’s worth the few bucks since you can do so many other things with it.

      Note: You can also use OS X’s bulit-in method described here or any other keyboard mapping tools. BTT is the simplest though, in my opinion.
    2. Open BTT’s preferences by clicking the BTT Menu Bar Icon icon, located in the menu bar. Select Global on the left side (to ensure the shortcut will work from any app), then click + Add New Shortcut.Add Shortcut in BTT
    3. Under Keyboard Shortcut, type the key or shortcut combo you wish to use (F15 in this example) and then click on the Trigger Predefined Action drop-down box.Select Shortcut in BTT
    4. In the search box that pops-up, type:
      apple script

      and then select Open Application / File / Apple Script …BTT Search Box with "Apple Script"

    5. Navigate to the saved .scpt file from earlier and select it. Click Open.Select AppleScript in BTT
    6. You can close the BTT window, as it will stay running in the background and accessible via the menu bar.

There you go!

17 Comments

  1. Any update to this for Sierra? It’s running fine for me in compile in Automator or Apple Script Editor (after a minor tweak to select “Scroll area 2” and “row 6”), but as soon as I save it as a service or app I get an error. It doesn’t seem to select the Display option, after it opens the Accessibility pane. Love to hear if you have it working!

    1. Same, sierra broke my AppleScript.
      I’m having trouble customizing it to access the Display anchor menu.
      `reveal anchor “Display” of pane id “com.apple.preference.universalaccess”`
      spits out an error.

    2. Hey, I got it working:

      tell application “System Preferences”
      activate
      set the current pane to pane id “com.apple.preference.universalaccess”

      tell application “System Events” to tell process “System Preferences”
      tell window “Accessibility”
      tell scroll area 1
      tell table 1
      select row 6

      end tell

      end tell
      click checkbox “Use grayscale”
      end tell

      end tell
      end tell
      #tell application “System Preferences” to quit

  2. ^ I made a mistake in the last script (feel free to delete it)

    Here’s is my new one, working for OSX Sierra.
    —————
    tell application “System Preferences”
    activate
    set the current pane to pane id “com.apple.preference.universalaccess”
    delay 1 # needs time to open universal access
    tell application “System Events” to tell process “System Preferences” to tell window “Accessibility”
    tell scroll area 2 to tell table 1 to tell row 6 #open display preferences

    select

    end tell

    click checkbox “Use grayscale”
    end tell
    end tell

    tell application “System Preferences” to quit

  3. Hi there. Running Mac OS High Sierra, and curious about a script to do this for the newest operating system. Tried the solution offered above (Seth’s corrected post), and got a “Syntax Error” dialog.

    1. I’ve found a solution for High-Sierra (based on code from here as well as code from https://apple.stackexchange.com/questions/240446/how-to-enable-disable-grayscale-mode-in-accessibility-via-terminal-app/240449). Also, I’d recommend saving it as an app and putting the app in your dock to keep things simple (advice from https://apple.stackexchange.com/questions/196761/how-to-toggle-with-grayscale-in-yosemite).

      High-Sierra code:
      ————-

      tell application “System Preferences”
      activate
      reveal anchor “Seeing_Display” of pane id “com.apple.preference.universalaccess”
      end tell
      delay 0.3
      tell application “System Events” to tell process “System Preferences” to tell window “Accessibility”
      click the checkbox “Use grayscale”
      end tell
      tell application “System Preferences”
      quit
      end tell

    1. @Joshua: Sorry, there was an error in the post. Changing all “ to ” in the script should make it run correctly.

  4. Unquestionably believe that which you stated. Your favorite reason seemed to be on the web the simplest thing
    to be aware of. I say to you, I certainly get irked while
    people consider worries that they plainly do not know about.

    You managed to hit the nail upon the top and also defined out the whole
    thing without having side effect , people can take a signal.

    Will probably be back to get more. Thanks

  5. The best in class, Depoxito present you high-end experience
    that direct the see and air of true VIP standarts, we present you
    the best tempting to high-level experience of VIPs expect in any top stop casino, grand stir casino royale offer you the further studio design element including the grand blackjack,
    offering our VIP Customer the best experience of
    a Salon privee table.
    New style table as well as feature across the room next grand roulette upgraded on our provider playtechs mini prestige roulette which delivering
    more engaging and richer playing experience.

    The new experience contains a total of seven tables including five
    blackjack tables, one roulette table and one baccarat table.
    Grand rouse casino royale has been tall hand-engineered to fit the needs
    of our customer to using it, and contains unique
    elements that is specially meant to maximize the impact value we got from our customers and
    diversify it to the existing network.
    Soon, Depoxito will fabricate an better certainty technology upon breathing casino for our VIP member, these most radical technology ever seen in stir casino including this greater than before reality.

    Which permit players to experience products on an entire additional level which is never seen since literally leaping out of the game and taking the blackjack, baccarat, roulette and
    further game into the summative entire level.

    Depoxito VIP Baccarat, we meet the expense of you the no question exclusive living VIP Baccarat that is played afterward stirring to 7 players at the same table and our severely trained beautiful stir baccarat
    dealer. And of course our VIP aficionada will character as
    if they were in point of fact sitting at one of the summit casino baccarat table.
    This immersive gaming experience creates a hugely thrill-seeking
    announce that our VIP players will find hard to surpass.

    Here is the list of conscious casino game that depoxito provide, we provide the
    widest range of sentient casino games on the spread
    around including : blackjack unlimited, blackjack prestige,
    roulette, baccarat, poker, hi-lo, sic bo, and grand sentient casino royale such as Grand
    Baccarat, Grand Blackjack and Grand Roulette for our VIP member.
    And of course as a aficionado of Depoxito you can enjoy all the
    games that we manage to pay for to you, every you compulsion to attain is just visit our site
    http://www.depoxito.com and register it solitary takes in the works to 3 minutes and subsequently youre okay to fake any game that
    you want.
    Be our VIP, monster our VIP supporter of course decided you the
    best relieve you can get from us all you infatuation to
    be a VIP supporter is no question easy. every you craving is just keep playing upon our site, addition and play a
    role considering a VIP as soon as the amount that our company had written, keep playing and our customer bolster will gate you that you are promoted to become
    a VIP advocate on our site.

  6. I cannot express enough thanks for this script. It is the end of the 2019 year and I have struggled to find a simple shortcut solution for grayscale that works properly. This is an essential feature that should have been implemented by Apple in the beginning.

    Ontario, Canada

Leave a Reply

Your email address will not be published. Required fields are marked *