timproved cross-platform compitability - 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
---
(DIR) commit 6e53bfc3f3450820838e6a257272aef9629156e1
(DIR) parent 023059a8551d7d64d80d75131b31df1f4acf6aeb
(HTM) Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date: Fri, 30 Jan 2015 09:49:59 +0100
improved cross-platform compitability
Diffstat:
M exercise_time.sh | 43 ++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 10 deletions(-)
---
(DIR) diff --git a/exercise_time.sh b/exercise_time.sh
t@@ -1,7 +1,8 @@
#!/bin/bash
# IT'S EXERCISE TIME!
-# Requires the `festival` speech synthesizer or a notification daemon.
+# Requires the `festival` speech synthesizer if on Linux and/or a notification
+# daemon such as `dunst`.
### I have the following entries in my user's cron tab (`crontab -e`)
# # m h dom mon dow command
t@@ -33,16 +34,38 @@ fi
# announce exercise the specified number of times
UNAMESTR=`uname`
for ((i=0; i<$1; i++)); do
- #mpc pause &> /dev/null
- if [[ "$(ifconfig | grep 10.17.8)" ]]; then
- if [[ "$UNAMESTR" == 'Darwin' ]]; then
- say "It's exercise time! $2"
- else
- echo "It's exercise time! $2" | festival --tts
+
+ announcement="It's exercise time! $2"
+
+ # Send message to notification daemon
+ if command -v notify-send &>/dev/null; then
+ notify-send "$announcement"
+ fi
+
+ # Use speech synthesis if the computer is plugged in at my office desk
+
+ # OS X
+ if [[ "$UNAMESTR" == 'Darwin' ]]; then
+ if [[ "$(ifconfig | grep 10.17.8)" ]]; then
+
+ say "$announcement"
+ fi
+
+ # Linux
+ elif [[ "$UNAMESTR" == 'Linux' ]]; then
+
+ if [[ "$(ip addr | grep 10.17.8)" ]]; then
+ if command -v mpc &>/dev/null; then
+ mpc pause &> /dev/null
+ fi
+ if command -v festival &>/dev/null; then
+ echo "$announcement" | festival --tts
+ fi
+ if command -v mpc &>/dev/null; then
+ mpc play &> /dev/null
+ fi
fi
- else
- notify-send "It is exercise time! $2"
fi
- #mpc play &> /dev/null
+
sleep $WAITSECS
done