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:

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:

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.

Permanent Link for Post

Scheduling Color Temperature Changes for Your Monitors (2025-06-07)

Older Posts

  1. Stream and Play: Emulating Retro Games on Chromecast with Google TV (2025-05-10)
  2. Simulating the Monty Hall Problem (2025-05-04)
  3. Pi-hole on Raspberry Pi OS with dnscrypt-proxy (2024-01-28)
  4. Prime or Not Prime: That is the Question (2023-07-22)
  5. Switching Monitor Inputs on Computer Wakeup (2021-04-25)
  6. Changing the Playback Speed on Spotify's Web Player (2021-04-24)
  7. Solving Microcorruption Hollywood (2021-03-28)
  8. Font Rendering on macOS (2020-07-02)
  9. Video Disk Recorder (VDR) Tooling (2020-05-30)
  10. Spotify Web Player Failure due to Crash of Connected Device (2020-05-08)
  11. Malicious Forward Proxies (2020-04-27)
  12. Switching to a Dark Theme (2020-04-25)
  13. USB 3.0 to Gigabit Ethernet Adapter with Realtek 8153 Chipset on macOS Catalina (2020-04-23)
  14. Backing up Emails using OfflineIMAP (2020-04-19)
  15. Using a Raspberry Pi as a Wireless Access Point (2020-04-18)
  16. Accessing External Hard Drives in a Virtual Machine (2017-12-11)
  17. Managing Clipboards (2016-11-23)
  18. Multi-Screen Configuration Using Xrandr (2016-07-02)
  19. Email Backup and Migration using Thunderbird (2016-06-29)
  20. Automatic SSH Proxy Selection (2016-02-08)
  21. Set Color Temperature (2015-11-25)
  22. Completion Methods in Vim (2015-10-10)
  23. Fuzzing the mbed TLS Library (2015-09-26)
  24. SSH Weak Diffie-Hellman Group Identification Tool (2015-08-12)
  25. Building a Standing Desk for 50 Bucks (2015-01-25)
  26. High-DPI Displays under Linux (2014-12-23)
  27. Slow Wi-Fi on the Raspberry Pi (2014-06-15)
  28. XBMC on the Raspberry Pi (2014-06-14)
  29. Turning the Raspberry Pi into a Game Console (2014-06-12)
  30. ZFS Backups to External Hard Drives (2014-03-23)
  31. Display the I/O Usage of a Process (2014-02-21)
  32. Determining Wireless Network Channel Usage (2014-02-09)
  33. Managing Web Files through a Repository (2013-08-17)
  34. Simple HTTP File Servers (2013-08-16)
  35. Protect your SSH Private Keys (2013-06-16)
  36. Forward Secrecy for HTTPS and Ephemeral Diffie-Hellman (2013-06-14)
  37. Markdown Preview Chrome Extension (2013-06-13)