How can I script inverting screen colors?
And, more generally, how can I change accessibility settings via the command line?
Worth pointing out that I'm pretty comfortable with bash already- coming from a systems administration / *nix background- but I just don't know which files to edit or tools to use.
To clarify, I am not asking this question, the resolution of which modifies a setting under Security and Privacy. What I want to do is change a setting directly under Accessibility. I'll grant the title of that question is misleadingly similar, but the content is entirely divorced from my intent.
-
If it's okay to give
Terminal.app
permanent access toAccessibility
:- Open
System Preferences
- Go to
Security & Privacy
section - In
Privacy
tab, click on the lock in bottom left and enter your password to enable editing - Select
Accessibility
from left side list and then checkTerminal
checkbox in right side list (if there is noTerminal
checkbox here you might run step 5 once and then back to this step) -
Open
Terminal
and run this line (it uses AppleScript):osascript -e "tell application \"System Preferences\"" -e "activate" -e "reveal anchor \"Seeing_Display\" of pane id \"com.apple.preference.universalaccess\"" -e "tell application \"System Events\" to tell process \"System Preferences\"" -e "click the checkbox \"Invert colors\" of window \"Accessibility\"" -e "end tell" -e "quit" -e "end tell"
repeating previous steps for the future is not needed.
- Open
-
If it's not okay to give direct access:
- Open
System Preferences
- Go to
Keyboard
section - In
Shortcuts
tab, SelectAccessibility
from left side list and then checkInvert colors
in right side list (Default shortcut isctrl
+alt
+cmd
+8
). -
Open
Terminal
and run this line (it uses AppleScript):osascript -e "tell application \"System Events\"" -e "key code 28 using {control down, option down, command down}" -e "end tell"
repeating previous steps for the future is not needed.
- Open
You can write those codes in external script files and run with osascript invertColors.scpt
to invert: printf '\e[?5h'
to un-invert: printf '\e[?5l'