Skip to content

Instantly share code, notes, and snippets.

@nirbheek
Created December 11, 2014 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nirbheek/bfbf4f486f53fedccf0e to your computer and use it in GitHub Desktop.
Save nirbheek/bfbf4f486f53fedccf0e to your computer and use it in GitHub Desktop.
#!/bin/bash
# vim: set sts=2 sw=2 et :
#
# Author: Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
# License: BSD
#
# Mutes $MUSIC_APP_NAME when $APP_NAME starts playing something
APP_NAME="lt-stream-app"
MUSIC_APP_NAME="Rhythmbox"
MUTED_BY_US=0
get_sink_input_id_from_app_name() {
local app_name=$1
pactl list sink-inputs | grep -B 20 "application.name = \"$app_name\"" \
| grep "Sink Input" | cut -f2 -d\#
}
while true; do
sleep 0.5
app_id=$(get_sink_input_id_from_app_name "$APP_NAME")
music_id=$(get_sink_input_id_from_app_name "$MUSIC_APP_NAME")
if [[ -z $music_id ]]; then
echo "Music player is not playing?"
continue
fi
if [[ -n $app_id ]]; then
if [[ $MUTED_BY_US == 0 ]]; then
pactl set-sink-input-mute "$music_id" 1
MUTED_BY_US=1
echo "Music player muted"
fi
elif [[ $MUTED_BY_US == 1 ]]; then
pactl set-sink-input-mute "$music_id" 0
echo "Music player unmuted"
MUTED_BY_US=0
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment