From a058a2f3d8e4b583a85e4fb69cbcaf555e7c00a1 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Fri, 1 Apr 2011 21:00:07 +1100 Subject: [PATCH] mediawrap: added options and max delay --- mediawrap | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/mediawrap b/mediawrap index 7a19264..3b516cc 100755 --- 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" -- 2.39.2