Created
December 11, 2014 12:28
-
-
Save nirbheek/bfbf4f486f53fedccf0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# vim: set sts=2 sw=2 et : | |
# | |
# Author: Nirbheek Chauhan <[email protected]> | |
# 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