]> code.delx.au - mediapc-tools/blobdiff - mediawrap
monitor-dir: track changes in a directory
[mediapc-tools] / mediawrap
index 7a19264bcb05222c5c7a9995d111fc61ede4dd0a..764c8bf0f773700a940da4de9400d74724a1ec38 100755 (executable)
--- a/mediawrap
+++ b/mediawrap
@@ -4,39 +4,59 @@ 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
        if [ "$(ps -o cmd= -p "$(cat "$PIDFILE")" | wc -l)" -eq 0 ]; then
+               rm -f "$PIDFILE"
                break
        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"