Scheduling Color Temperature Changes for Your Monitors
2025-06-07
In this post, I'll explain how to set up a cron job that changes the color temperature of your monitors using xsct, a command-line tool for X server maintained by me.
Installation
To get started, you need to install xsct:
- On Debian or Ubuntu, run: apt install xsct
- On Arch Linux, run: pacman -S xsct
Creating the Shell Script
Create a shell script named .wakeup.sh in your home directory with the following content:
#!/usr/bin/env bash main () { # Between 6 PM and 6 AM, set the color temperature to 3000 K. # During other hours, set the display brightness to 6500 K. local -r hour=$(date '+%H') local temp=6500 if [ $hour -lt 6 ] || [ $hour -ge 18 ] then temp=3000 fi /usr/bin/xsct "$temp" } date main
This script checks the current hour and sets the color temperature accordingly:
- From 6 PM until 6 AM, the color temperature is adjusted to a warm 3000 K to support better sleep.
- From 6 AM until 6 PM, the color temperature is set to 6500 K, providing a cooler tone that is more suitable for daytime use.
Setting Up the Cron Job
To set up a cron job to run this script every 5 minutes, open your crontab with:
crontab -e
Add the following line, replacing myuser with your actual username:
*/5 * * * * DISPLAY=:0 /home/myuser/.wakeup.sh >/tmp/.wakeup.txt 2>&1
This cron job will execute the script every 5 minutes and log the output to /tmp/.wakeup.txt.
Using Sunwait for Accurate Timing
Sunwait is a command-line tool that calculates sunrise and sunset times for a given location. By integrating Sunwait into your setup, you can get accurate sunrise and sunset times for your location.
Extending Your Script for More Gradual Adjustments
To enhance your lighting setup, consider adjusting the color temperature more frequently throughout the day in smaller increments. For example, you could transition smoothly from 3000 K in the morning to 6500 K during peak daylight hours, before gradually returning to warmer tones in the evening.