I prefer to keep the appearance setting to auto, so that my computer will be in light mode during the day and in dark mode at night.

Appearance Pane in the macOS System Preferences app that shows the Appearance set to Auto

But sometimes when working in a particularly dim or an exceedingly bright room, I like to override this using this simple shortcut here:

Shortcut that has one instruction: Toggle appearance

This would work, but then permanently set it to the opposite value, say I’d invoke the shortcut during the day, it would set it to dark mode and stay that way forever.

Even weirder: The Auto option isn’t even available via the Shortcuts interface. So you’d have to remember1 to go to the System Preferences and switch it back to auto or keep manually switching using the Shortcut.

2nd approach: Programmatically setting the value

macOS stores all settings in .plist files, which can be accessed using the defaults command. The automatic switching and interface style can be found under the following keys:

AppleInterfaceStyleSwitchesAutomatically = 1
AppleInterfaceStyle = Dark

But for the changes to the .plist to take effect you’d have to log out and log in again, which is not optimal for a casual action.

3rd approach: Telling UI Automator to tell macOS to switch

The UI Automator can override the values both immediately and will not overwrite the the auto setting.

tell application "System Events" to tell appearance preferences to set dark mode to not dark mode

This now properly works, while being overly complicated (Shortcut running Apple Script, invoking UI Automator to change a simple value in a .plist) it ticks all the boxes for me.

  1. or notice days later