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:
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
- Open Script Editor.app, located in Applications>Utilities.
- 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
- Click Compile, then Run to verify it works. Preview:
- Save the script file (.scpt).
Assign Script to a Keyboard Shortcut
- 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.
- Open BTT’s preferences by clicking the 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.
- 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.
- In the search box that pops-up, type:
- Navigate to the saved .scpt file from earlier and select it. Click Open.
- You can close the BTT window, as it will stay running in the background and accessible via the menu bar.
There you go!