├── buzzer.sh ├── README.md └── alarm.sh /buzzer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # The sound playing script for alarm.sh, modify this to include your alarm tone 4 | # The script requires mplayer to be installed on your system to run 5 | # Copyright (C) 2012, Sankha Narayan Guria (sankha93@gmail.com) 6 | # 7 | # These scripts are unlicensed. That is, they are in the public domain and free to use in any capacity for any purpose. 8 | 9 | # Put the file you want to play here instead 10 | file="/home/sankha/a1a.mp3" 11 | 12 | mplayer -really-quiet $file 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Alarm Clock 2 | 3 | #### Sankha Narayan Guria ([sankha93@gmail.com](mailto:sankha93@gmail.com)) 4 | 5 | This is just a simple shell script that acts as an alarm clock. A natural consequence of my habit of sleeping on the laptop! So nothing seemed better than turning my laptop into an alarm clock to wake me up. Currently this works on a Linux system and needs `mplayer` to be installed. 6 | 7 | #### To Use 8 | Download all the scripts and run the following in a terminal: 9 | 10 | `./alarm.sh` 11 | 12 | In the `buzzer.sh` file change the `file` variable. To change the snooze time change the `snooze` variable in the file `alarm.sh`. 13 | -------------------------------------------------------------------------------- /alarm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # A simple alarm clock script 4 | # Copyright (C) 2012, Sankha Narayan Guria (sankha93@gmail.com) 5 | # 6 | # These scripts are unlicensed. That is, they are in the public domain and free to use in any capacity for any purpose. 7 | 8 | # enter the time in seconds for which you want to snooze the alarm here 9 | snooze=10 10 | 11 | echo "After how much time should the alarm go off? (HH:MM:SS)" 12 | read arr 13 | 14 | OLD_IFS="${IFS}" 15 | IFS=":" 16 | read -r h m s <<< "$arr" 17 | seconds=$((( h * 60 * 60) + ( m * 60) + s )) 18 | start=$(date +%s) 19 | end=$((start + seconds)) 20 | cur=$start 21 | while [[ $cur -lt $end ]] 22 | do 23 | cur=$(date +%s) 24 | left=$((end-cur)) 25 | printf "\rTime to wake up : %02d:%02d:%02d" $((left/3600)) $(( (left/60)%60)) $((left%60)) 26 | 27 | sleep 1 28 | done 29 | IFS="${OLD_IFS}" 30 | echo 31 | 32 | # entering the infinite loop that will the play the alarm tone paused by the snoozing time 33 | while 34 | ./buzzer.sh 35 | do 36 | start=$(date +%s) 37 | end=$((start + snooze)) 38 | cur=$start 39 | while [[ $cur -lt $end ]] 40 | do 41 | cur=$(date +%s) 42 | left=$((end-cur)) 43 | printf "\rSnoozing for : %02d:%02d:%02d" $((left/3600)) $(( (left/60)%60)) $((left%60)) 44 | 45 | sleep 1 46 | done 47 | done 48 | --------------------------------------------------------------------------------