Invert Colors and Toggle Grayscale with JavaScript on macOS

Via reboot81:

Open Script Editor and paste each block into a new script for you to use.

Invert Colors

var systemEvents = Application("System Events");
var systemPreferences = Application("System Preferences");

systemPreferences.activate();

systemPreferences.panes.byId(
    "com.apple.preference.universalaccess"
  ).anchors.byName("Seeing_Display").reveal();


chkInvert = systemEvents.applicationProcesses.byName(
    "System Preferences"
  ).windows.byName("Accessibility").checkboxes.
      byName("Invert colors");

systemEvents.click(chkInvert);

systemPreferences.quit();

Toggle Grayscale

var systemEvents = Application("System Events");
var systemPreferences = Application("System Preferences");

systemPreferences.activate();

systemPreferences.panes.byId(
    "com.apple.preference.universalaccess"
  ).anchors.byName("Seeing_Display").reveal();


chkInvert = systemEvents.applicationProcesses.byName(
    "System Preferences"
  ).windows.byName("Accessibility").checkboxes.
      byName("Use grayscale");

systemEvents.click(chkInvert);

systemPreferences.quit();

macOS 12 Sierra Brew Users: Read This Before Updating Anything

When I update Brew I minimize the terminal window so I can work on something else while it is running. Every so often I check to see if it finished. Then I read through the history to see if there is any work I need to perform by hand. For example sometimes Brew can’t link things and other times the package won’t even install. This has always worked well. Today I had a funny surprise though.

Continue reading “macOS 12 Sierra Brew Users: Read This Before Updating Anything”

(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’

(macOS) Handling Too Many Application Windows Overload on macOS

My desk has 3 monitor on it—two external and one built into the Mac. They are used like this:

  • Top left
    • Chrome
    • Maybe
      • Inkscape
      • VMWare
      • iTunes
  • Top right
    • Emacs
  • Bottom
    • Terminal
    • WhatsApp
    • Pulse SMS

I tried to keep it simple but it is still easy to forget which application that I’m working with. I wanted a way to highlight the window that had focus and I found it with HazeOver — Distraction Dimmer for Mac.

Continue reading “(macOS) Handling Too Many Application Windows Overload on macOS”

Find All Locations Of A Binary Using `type’ not `which’

I can’t find the git 2.10 binary so I run

which git

/usr/local/bin/git

Excellent, found it.

And then I check it’s version to verify I am looking at the right version

/usr/local/bin/git –version

git version 2.21.0

Oops that isn’t what I wanted.

There must be another git getting loaded earlier in the search path.

Here is how to find out where all copies of git live

type -a git

git is /usr/local/bin/git
git is /usr/local/bin/git
git is /usr/bin/git

Look for the right git at version 2.10

/usr/local/bin/git –version
/usr/bin/git –version

git version 2.21.0
git version 2.14.3 (Apple Git-98)

I want the second one.

That is how to track down the location of a binary file on macOS that appears multiple times in the search path.

(macOS) Manage Multiple Snippets Of Copied Text With Your Clipboard With Flycut

After using it for a few days I already love it.

Personal examples:

  • I have a document open, and I want copy a few parts from it, into an email. But I don’t want to have to command-tab between the document and the email. So I just comand-c… and then go to my email. I do that all the time.
  • When I care about something that I am reading, a phrase, a word, and I want to remember it… maybe. So, the copy buffer is persistent, and I can go back anytime and look up what I may wanted to use.

Flycut: It’ll Remember It For You (but not Wholesale ).

If you are an Emacser you’ll instantly know and love this as a macOS Kill Ring.

Security concern: persisting sensitive information in your clipboard like this, it is easy to forget about it. Fortunately Flycut doesn’t copy values from password fields. Additionally it keeps it’s data local to your computer never sharing it between your other computers or devices. However, it is just like any other security concern so be careful what you keep in there.

Fix For When Bash Can’t Find Its Debugger On macOS

Sometimes Bash needs its debugger but it can’t find it. It looks like this:

/usr/share/bashdb/bashdb-main.inc: No such file or directory
-bash: warning: cannot start debugger

For example when you start bashdb yourself with bash --debugger or set shopt -s extdebug. Another example is when your terminal turns it on.

Here is the fix that worked on my box:

brew install bashdb
bashhome=$(brew –prefix bash)
bdbhome=$(brew –prefix bashdb)
ln -s $bdbhome/share/bashdb $bashhome/share/bashdb
unset bashhome
unset bdbhome