A shell script to change between MacOS dark mode and light mode

If you want to create a shell script so you can change between MacOS dark mode and light mode from the Terminal (Unix) command line, put this source code in a file and name it something like dark:

osascript -e \
'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode'

Then make that file executable, and make sure it’s on your PATH. Now you can type dark to toggle back and forth between dark mode and the regular light mode:

$ dark

From looking at that AppleScript code you would think you’d need two shell scripts for this purpose, but for some reason that one command toggles back and forth between the two MacOS modes.