(AppleScript+macOS) Maybe The Only Working Applescript For Toggling Grayscale And Inverting Colors On macOS Sierra In The World

2021-04-16: Here is one in JavaScript.

THANK YOU SILESKY

Toggle Grayscale

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

# Sierra: System Preferences -> Accessibility -> Display -> Use grayscale

Invert Colors

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 "Invert colors"
  end tell
end tell

tell application "System Preferences" to quit

# Sierra: System Preferences -> Accessibility -> Display -> Invert colors

Aliases

Run them from the command line. Maybe make your screen black and white at night or invert colors for screencasts or working in sunligh.

alias togglegrayscale=’osascript /Users/gcr/util/sspadtogglegrayscale.scpt’
alias invertcolors=’osascript /Users/gcr/util/sspadtogglecolors.scpt’

Leave a Reply

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