texercise_time.sh - exercise_time - announce workout exercises with notifications and speech synth
(HTM) git clone git://src.adamsgaard.dk/exercise_time
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
texercise_time.sh (3126B)
---
1 #!/bin/sh
2
3 # IT'S EXERCISE TIME!
4 # Requires the `festival` speech synthesizer if on Linux and/or `libnotify-bin`
5 # and a notification daemon such as `dunst`. On OS X `growl` can be used as the
6 # notification daemon.
7
8 ### I have the following entries in my user's cron tab (`crontab -e`)
9 # # m h dom mon dow command
10 # # Even days: Triceps and chest
11 # 55 */2 2-30/2 * * DISPLAY=:0 bash ~/code/exercise_time/exercise_time.sh 2 "Do ten push ups"
12 # 55 1-23/2 2-30/2 * * DISPLAY=:0 bash ~/code/exercise_time/exercise_time.sh 3 "Use the barbells for a triceps exercise fifteen times."
13 #
14 # # Odd days: Biceps and legs
15 # 55 */2 1-31/2 * * DISPLAY=:0 bash ~/code/exercise_time/exercise_time.sh 3 "Do ten squats with weights in hand."
16 # 55 1-23/2 1-31/2 * * DISPLAY=:0 bash ~/code/exercise_time/exercise_time.sh 3 "Use the barbells for a biceps exercise ten times."
17
18 # Wait time in seconds between sets
19 WAITSECS=120
20
21 # Announce via speech synth (0: No, 1: Yes)
22 SPEECHSYNTH=1
23
24 usage() {
25 echo "Usage: ${0##*/} <SETS> <EXERCISE>"
26 echo "Example: For three sets of ten pushups, use:"
27 echo " $0 3 'Do ten push ups'"
28 }
29
30 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
31 usage
32 exit 0
33 fi
34
35 # stop mpd if it is running
36 #mpc pause > /dev/null 2>&1
37
38 UNAMESTR="$(uname)"
39
40 # announce exercise the specified number of times
41
42 # Only send notification at work
43 if [ "$UNAMESTR" = "Darwin" ]; then
44 IP=$(/sbin/ifconfig | grep 10.9.62) # Sayre Hall
45 else
46 IP=$(ip addr | grep 192.168.0)
47 fi
48
49 for i in $(seq 1 "$1"); do
50
51 announcement="It's exercise time! $2"
52
53 # Send message to notification daemon if computer is plugged in at my office
54 # desk
55 if [ -n "$IP" ]; then
56
57 # OS X
58 if [ "$UNAMESTR" = "Darwin" ]; then
59 osascript -e "display notification \"$2\" with title \"It's exercise time\""
60
61 # Linux
62 elif [ "$UNAMESTR" = "Linux" ]; then
63 notify-send "$announcement"
64 fi
65 fi
66
67 # Use speech synthesis if the computer is plugged in at my office desk
68 if [ $SPEECHSYNTH -eq 1 ]; then
69
70 # OS X
71 if [ "$UNAMESTR" = "Darwin" ]; then
72 if [ -n "$IP" ]; then
73 say "$announcement"
74 fi
75
76 # Linux
77 elif [ "$UNAMESTR" = "Linux" ]; then
78
79 playingmusic=0
80
81 if [ -n "$IP" ]; then
82 # if command -v mpc >/dev/null 2>&1; then
83 # if [ "$(mpc | grep playing)" ]; then
84 # mpc pause > /dev/null 2>&1
85 # sleep 2
86 # playingmusic=1
87 # fi
88 # fi
89 if command -v festival >/dev/null 2>&1; then
90 echo "$announcement" | festival --tts
91 fi
92 if command -v mpc >/dev/null 2>&1; then
93 if [ $playingmusic -eq 1 ]; then
94 sleep 2
95 mpc play > /dev/null 2>&1
96 fi
97 fi
98 fi
99 fi
100 fi
101
102 if [ "$i" -lt "$(echo "$1" | bc -l)" ]; then
103 sleep $WAITSECS
104 fi
105 done