Just a few days ago I went grayscale on my phone in order to reduce the distraction from all the vivid App Icon colors and badges. This is just on tweak mentioned by the http://www.timewellspent.io/ movement.
I was pleasantly surprised by the outcomes of it, I use my phone less and my life outside my phone now feels brighter and more colorful. Those extreme colors of apps and website make real world colors seem a bit dull after a while I guess.
On my phone I managed to turn on the grayscale feature by tapping my on/off button 3 times, this is quite useful, because often times you need some colors on your phone. For example when taking or watching pictures.
Now I wanted to go a step further and even use the grayscale feature on my mac. Enabling and disabling the feature in the Accessibility Section of the System Preferences is super annoying. Therefore, I wanted to add a keyboard shortcut using Hammerspoon. There is already an extension called screen which let's you read the Accessibility Settings, however, it is unable to manipulate these.
Unfortunately, I'am not a big Lua developer to implement this by myself, I hope someone find's this useful as well and implement this feature to the screen extension.
@Pczek - You could try something like this:
hs.osascript.applescript([[
tell application "System Preferences"
activate
reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences"
click the checkbox "Use grayscale" of window "Accessibility"
end tell
tell application "System Preferences"
quit
end tell
]])
You could also do a Terminal command like:
defaults write com.apple.universalaccess grayscale true
However, which will update the Preferences, but I'm not sure how you tell macOS to refresh the screen. Any ideas @asmagill ?
There's a way of doing it via Terminal here, but it requires disabling System Integrity Protection. AppleScript seems like the only way to do it without messing with SIP.
Thanks for all the research 馃憤馃徏. I will definitely try it out using apple script. Nevertheless, in my opinion the hs.screen module should be able to do this in the future.
Thoughts @asmagill & @cmsj ?
The macOS API we use to get those settings in hs.screen unfortunately doesn't let you manipulate them, e.g. https://developer.apple.com/documentation/appkit/nsworkspace/1524656-accessibilitydisplayshoulddiffer?language=objc - note that it's marked as readonly.
It'd be great if there is a way to change those settings, but I'm not aware of one, so something like the AppleScript route is probably the way to go for now. Sorry!
@cmsj - Do you have any objections if we added this AppleScript code to hs.screen if it can't be done via Objective-C APIs?
@latenitefilms so long as it works reliably, I'm fine with adding it.
Note: There is an undocumented objective C API for setting the lower-level graphics setting. See https://stackoverflow.com/a/35676240/303931 and https://apple.stackexchange.com/a/342551/310325
CG_EXTERN bool CGDisplayUsesForceToGray(void);
CG_EXTERN void CGDisplayForceToGray(bool forceToGray);
It doesn't update the setting in System Preferences which could be confusing, but also doesn't persist after a reboot.
Leaving this for people who want to use AppleScript to toggle greyscale.
This works in macOS Mojave, the snippet above does not. Something weird about how Mojave now handles windows.
tell application "System Preferences"
activate
reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell process "System Preferences"
repeat until exists of checkbox "Use greyscale" of group 1 of window "Accessibility"
delay 0.1
end repeat
click the checkbox "Use greyscale" of group 1 of window "Accessibility"
end tell
tell application "System Preferences"
quit
end tell
Mind the greyscale/grayscale (UK vs US English).
For anyone stumbling upon this thread in hope to set the grayscale accessibility option. Since the most recent update of hammerspoon 0.9.74 there are two new hs.screen functions to check if grayscale is enabled, disable and enable it.
hs.screen.setForceToGray(ForceToGray) -> None
hs.screen.getForceToGray() -> boolean
https://www.hammerspoon.org/docs/hs.screen.html#setForceToGray
Most helpful comment
Leaving this for people who want to use AppleScript to toggle greyscale.
This works in macOS Mojave, the snippet above does not. Something weird about how Mojave now handles windows.
Mind the greyscale/grayscale (UK vs US English).