Skip to content

Instantly share code, notes, and snippets.

@jpic
Created February 12, 2013 09:07
Show Gist options
  • Save jpic/4761102 to your computer and use it in GitHub Desktop.
Save jpic/4761102 to your computer and use it in GitHub Desktop.
Alarm script proof of concept that works even if your computer is in hibernation.
#!/bin/bash
set -x
MUSIC=(~/Music/Africando\ -\ All\ Stars\ Betece/*mp3)
START="$(date +%s -d 'tomorrow 08:00')"
#START="$(date '+%s' -d '+ 5 minutes')"
STOP="$(date '+%s' -d 'tomorrow 19:00')"
sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sudo sh -c "echo $START > /sys/class/rtc/rtc0/wakealarm"
if [[ "x$(</sys/class/rtc/rtc0/wakealarm)" -ne "x$START" ]]; then
echo "FAIL TO SET WAKE"
exit
fi
while (( $START > $(date +%s) )); do
sleep 1
done
for f in "${MUSIC[@]}"; do
if (( $(date +%s) > $STOP )); then
exit 0
fi
sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sudo sh -c "echo $(date '+%s' -d '+ 5 minutes') > /sys/class/rtc/rtc0/wakealarm"
mpg123 "$f";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment