How to use Night Shift on macOS with Keyboard Maestro

Table of contents:

# Introduction

In order not to tire my eyes, I turn on Night Shift. Night Shift can be turned on and off manually in the system settings (System Settings > Displays > Night Shift). But I don't want it to be on all the time, because the colors are then strange, especially when I'm watching movies and I care about the original colors.

I wanted to automate this process with Keyboard Maestro. I found a solution that works for me.

# Install nightlight CLI

nightlight is a command line tool for macOS to control Night Shift. It allows you to

  • enable/disable Night Shift
  • change the color temperature
  • set a schedule.

I installed it with Homebrew:

brew install smudge/smudge/nightlight

# Create Keyboard Maestro macros

I created two macros, one to enable Night Shift and one to disable it. These macros run a shell script that enables or disables Night Shift with the nightlight. I set them to keyboard shortcuts βŒƒβŒ₯β‡§βŒ˜Right Arrow and βŒƒβŒ₯β‡§βŒ˜Left Arrow (I use Karabiner-Elements to map Caps Lock to Command+Control+Option+Shift).

I also wanted to keep my schedule from 8pm to 7am with a temperature of 100%.

Important: You need to get the full path to the nightlight installed by Homebrew to run it in Keyboard Maestro. I found it with which nightlight command.

Script to enable Night Shift:

/opt/homebrew/Cellar/nightlight/0.3.0/bin/nightlight schedule 8pm 7am
/opt/homebrew/Cellar/nightlight/0.3.0/bin/nightlight temp 100

Script to disable Night Shift:

/opt/homebrew/Cellar/nightlight/0.3.0/bin/nightlight schedule stop
/opt/homebrew/Cellar/nightlight/0.3.0/bin/nightlight temp 0