#!/bin/sh # Makes my SGI do a single phone-ring sound, at top volume. # # But, if the screensaver is active, and it's between 2am and noon, # then ring at half volume (because I might be asleep.) # # jwz, 17-Jan-98 exec 2>&- >&- (echo `date` "--" $0 $* ) >&2 device='Analog Out' file=/u/jwz/sounds/phones/ring2.aiff volume='100%' half_volume='33%' query=false quiet=undefined # be quiet after 2am and before noon, if the screen is blanked. early_hour=12 late_hour=2 while $# ; do case "$1" in -query ) query=true shift ;; -loud ) quiet=false shift ;; -quiet ) quiet=true shift ;; * ) echo "usage $0 [ -query ] [ -loud | -quiet ]" exit 1 ;; esac done saver_status=undefined saver_active=undefined sleep_hour=undefined # If neither -quiet nor -loud has been specified, then look at the state # of xscreensaver and the time of day to determine whether to be quiet or # loud. # if [ "$quiet" = "undefined" ]; then saver_status=`xscreensaver-command -time 2>&-` saver_active=`echo $saver_status | sed -e 's/active/blanked/' -n -e 's/.* blanked .*/yes/p'` if [ "$saver_active" = yes ]; then set -x hour=`date '+%H' | sed 's/^0//'` sleeping=no if [ $late_hour -lt $early_hour ]; then # sleep period lies after midnight. if [ $hour -ge $late_hour -a $hour -le $early_hour ]; then sleeping=yes fi else # sleep period spans midnight. if [ $hour -ge $late_hour -o $hour -le $early_hour ]; then sleeping=yes fi fi if [ "$sleeping" = yes ]; then quiet=true else quiet=false fi fi fi # The -query argument means "just ask whether to be quiet or loud, but # don't actually make any noise." # if [ "$query" = true ]; then quiet=true if [ "$quiet" = true ]; then echo "quiet" else echo "loud" fi exit 0 fi if [ "$quiet" = true ]; then volume=$half_volume fi ( d=`date`; echo $d "-- quiet:" $quiet ; echo $d "-- volume:" $volume ; echo $d "-- status:" $saver_status ; echo $d "-- active:" $saver_active ; echo $d "-- sleep:" $sleeping ; ) >&2 # First find the old volume setting; # then change the system's global volume; # then play the sound; # then set the volume back to what it was before. # old_volume=` apanel -nodisplay -print | awk "/^Output Device Name:.*$device \(/,/^\$/" | sed -n 's/^[ ]*Gain:[ ]*\([-0-9.]*\), \([-0-9.]*\).*/\1 \2/p' ` apanel -nodisplay -device "$device" -gain $volume $volume playaifc -q $file exec apanel -nodisplay -device "$device" -gain $old_volume