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