]> code.delx.au - mediapc-tools/commitdiff
mediawrap: added options and max delay
authorJames Bunton <jamesbunton@fastmail.fm>
Fri, 1 Apr 2011 10:00:07 +0000 (21:00 +1100)
committerJames Bunton <jamesbunton@fastmail.fm>
Fri, 1 Apr 2011 10:00:07 +0000 (21:00 +1100)
mediawrap

index 7a19264bcb05222c5c7a9995d111fc61ede4dd0a..3b516cc7e5df1224d42442d9b81ba6d963424972 100755 (executable)
--- a/mediawrap
+++ b/mediawrap
@@ -4,7 +4,8 @@ PIDFILE="$HOME/.mediawrap.pid"
 PULSESTATE="$HOME/.pulseaudio.state"
 KEYPATH="/apps/gnome_settings_daemon/keybindings"
 
-while true; do
+# Wait for any other wrapped software to finish
+for i in $(seq 6); do
        if [ ! -r "$PIDFILE" ]; then
                break
        fi
@@ -13,30 +14,48 @@ while true; do
        fi
        sleep 0.5
 done
+if [ -r "$PIDFILE" ]; then
+       exit 1
+fi
+echo $$ > "$PIDFILE"
 
 # Disable volume keys
-gconftool --set --type string "$KEYPATH/volume_up" ''
-gconftool --set --type string "$KEYPATH/volume_down" ''
-gconftool --set --type string "$KEYPATH/volume_mute" ''
+if [ "$1" = "--disable-volume-keys" ]; then
+       disable_volume_keys=1
+       shift
+       gconftool --set --type string "$KEYPATH/volume_up" ''
+       gconftool --set --type string "$KEYPATH/volume_down" ''
+       gconftool --set --type string "$KEYPATH/volume_mute" ''
+fi
 
 # Unmute everything and turn volume to full
-pacmd 'dump' | grep 'set-sink' > "$PULSESTATE"
-cat "$PULSESTATE" | grep 'set-sink-mute' | awk '{print $2;}' | \
-       while read device; do
-               pacmd "set-sink-volume $device 0x10000" > /dev/null
-               pacmd "set-sink-mute $device no" > /dev/null
-       done
+if [ "$1" = "--max-volume" ]; then
+       max_volume=1
+       shift
+       pacmd 'dump' | grep 'set-sink' > "$PULSESTATE"
+       cat "$PULSESTATE" | grep 'set-sink-mute' | awk '{print $2;}' | \
+               while read device; do
+                       pacmd "set-sink-volume $device 0x10000" > /dev/null
+                       pacmd "set-sink-mute $device no" > /dev/null
+               done
+fi
 
 # Run the program
-"$@"
+"$@" &> /dev/null
+
 
 # Restore volume levels and mute status
-cat "$PULSESTATE" | pacmd > /dev/null
+if [ -n "$max_volume" ]; then
+       cat "$PULSESTATE" | pacmd > /dev/null
+fi
 
 # Enable volume keys
-gconftool --set --type string "$KEYPATH/volume_up" 'XF86AudioRaiseVolume'
-gconftool --set --type string "$KEYPATH/volume_down" 'XF86AudioLowerVolume'
-gconftool --set --type string "$KEYPATH/volume_mute" 'XF86AudioMute'
+if [ -n "$disable_volume_keys" ]; then
+       gconftool --set --type string "$KEYPATH/volume_up" 'XF86AudioRaiseVolume'
+       gconftool --set --type string "$KEYPATH/volume_down" 'XF86AudioLowerVolume'
+       gconftool --set --type string "$KEYPATH/volume_mute" 'XF86AudioMute'
+fi
 
+# Cleanup so other programs can start
 rm -f "$PIDFILE"