2

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.

0

4 Answers 4

4
  • If it's okay to give Terminal.app permanent access to Accessibility:

    1. Open System Preferences
    2. Go to Security & Privacy section
    3. In Privacy tab, click on the lock in bottom left and enter your password to enable editing
    4. Select Accessibility from left side list and then check Terminal checkbox in right side list (if there is no Terminal checkbox here you might run step 5 once and then back to this step)
    5. 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.

  • If it's not okay to give direct access:

    1. Open System Preferences
    2. Go to Keyboard section
    3. In Shortcuts tab, Select Accessibility from left side list and then check Invert colors in right side list (Default shortcut is ctrl+alt+cmd+8).
    4. 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.

You can write those codes in external script files and run with osascript invertColors.scpt

3

to invert: printf '\e[?5h'


to un-invert: printf '\e[?5l'

2
  • I know how to use terminal escape sequences. That's not the question I'm asking. Please try to understand what's being asked before you answer. :P Jul 25, 2017 at 4:03
  • ah you mean the entire screen. I have never used mac, but this is still useful if you want your terminal to flash after updating (what do you mac'ers use? homebrew?). Sorry about that and good luck with the osascripting. Also, after reading your question a second time, it still looks a bit like you meant the terminal if reading quickly.
    – Dylan
    Jul 25, 2017 at 12:09
0
defaults find invert

leads to

defaults read com.apple.CoreGraphics DisplayUseInvertedPolarity

Which returns 0 = normal, 1 = inverted. Alas, writing did not affect the screen in Mojave 10.14.6 but did confuse the ⌃⌥⌘8 shortcut.

1
0

On macOS Monterey or newer it’s now possible to toggle Smart and Classic Invert using the new Shortcuts app. Search for "Invert" in the Action list when creating a new shortcut.

Run shortcuts from the command line

You must log in to answer this question.

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