For a long while, I’ve had a disdain for the abrubt awakening caused by traditional alarm clocks. I wanted something that was still going to wake me, but wouldn’t cause my heart to be racing first thing in the morning. So I wrote some crontab entries to help:
0 5 * * * mpc vol 10
0 5 * * * mpc play
5 5 * * * mpc vol 20
5 5 * * * mpc play
10 5 * * * mpc vol 30
10 5 * * * mpc play
15 5 * * * mpc vol 40
15 5 * * * mpc play
20 5 * * * mpc vol 50
20 5 * * * mpc play
25 5 * * * mpc vol 60
25 5 * * * mpc play
30 5 * * * mpc vol 70
30 5 * * * mpc play
35 5 * * * mpc vol 80
35 5 * * * mpc play
40 5 * * * mpc vol 90
40 5 * * * mpc play
For those not used to reading crontabs, at 0500 set the volume to 10%, then start playing music, and every five minutes increase the volume by 10%, play the music again (as it might have been turned off), and continue to the normal listening volume (90% in this case).
Of course, writing that by hand is a pain, so I have an xs script generate that chunk of my crontab for me:
# User configurable values
max_vol = 90
min_vol = 0
hour = 5
min_step = 5
#####
# State variables
vol = $min_vol
min = 0
while {$vol :lt $max_vol} {
# Increment volume
vol = `($vol + 10)
cron = $min $hour \* \* \*
# %flatten takes a string and a list, it joins the list with the string
echo <={ %flatten \t $cron 'mpc vol '^$vol }
echo <={ %flatten \t $cron 'mpc play' }
# Increment minutes
min = `($min + $min_step)
}