From a1e2ced1c205086d399aea347b476f9334dd2c27 Mon Sep 17 00:00:00 2001 From: smarkoco Date: Tue, 27 Feb 2024 15:43:36 -0500 Subject: [PATCH 1/7] bug fix when having multiple audio sinks to not confuse processes --- README.md | 4 ++- adfree.sh | 2 +- mute_app.sh | 76 ++++++++++++++++--------------------------- mute_spotify_timer.sh | 14 +++++--- 4 files changed, 42 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 0b7e661..5d29a6c 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,14 @@ This is purely a bash script. Uses dbus, applicable for systems using PulseAudio. Only works while using Spotify client (doesn't matter how you install it) and not web browser. -Mutes and unmutes Spotify within 5 seconds of start and end of Ads. +Mutes and unmutes Spotify within 1 second of start and end of Ads. ### Usage: To use just run `mute_spotify_timer.sh` either using terminal or Alt + F2 launcher or just add it to list of system Startup Applications. To allow monitoring the ongoing status, run `adfree.sh` as a Startup Application, or with `bash adfree.sh`. It creates a new background tmux session called `adfree`, which can be connected to with `tmux a -t adfree`. +In adfree.sh, you may specify respawn=true + ### Maintenance: I'll make this more efficient when I'll feel free. Meanwhile you can send Pull Requests! diff --git a/adfree.sh b/adfree.sh index 5ee32bd..c060a84 100755 --- a/adfree.sh +++ b/adfree.sh @@ -1,3 +1,3 @@ #!/bin/bash tmux new-session -d -s adfree -tmux send-keys '~/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh' C-m # C-m sends ENTER keystroke +tmux send-keys "~/git/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh $respawn" C-m diff --git a/mute_app.sh b/mute_app.sh index 423a91b..d2fa20e 100755 --- a/mute_app.sh +++ b/mute_app.sh @@ -1,70 +1,50 @@ #!/bin/bash -# Script to mute an application using PulseAudio, depending solely on -# process name, constructed as answer on askubuntu.com:. -# http://askubuntu.com/questions/180612/script-to-mute-an-application - -# It works as: mute_application.sh vlc mute OR mute_application.sh vlc unmute +# Script to respawn or mute an application using PulseAudio +# it works as mute_app.sh , such as mute_app.sh spotify mute if [ -z "$1" ]; then - echo "Please provide me with an application name" + echo "Please provide an application name." exit 1 fi if [ -z "$2" ]; then - echo "Please provide me with an action mute/unmute after the application name" + echo "Please provide an action: mute, unmute, or respawn." exit 1 fi -if ! [[ "$2" == "mute" || "$2" == "unmute" ]]; then - echo "The 2nd argument must be mute/unmute" +if [[ "$2" != "mute" && "$2" != "unmute" && "$2" != "respawn" ]]; then + echo "The action must be mute, unmute, or respawn." exit 1 fi -process_id=$(pidof "$1") +# Get the process ID associated with the specified application +process_ids=$(pgrep -d ' ' -x "$1") -if [ $? -ne 0 ]; then - echo "There is no such process as "$1"" +if [ -z "$process_ids" ]; then + echo "There is no such process matching: '$1'." exit 1 fi -temp=$(mktemp) - -pacmd list-sink-inputs > $temp - -inputs_found=0; -current_index=-1; +# Loop through each process ID +for process_id in $process_ids; do + # Get the sink input index for the sink with "spotify" in the name + sink_input_index=$(pacmd list-sink-inputs | grep -B 20 -P "application.name = \"${1}\"" | grep "index" | awk '{print $2}') -while read line; do - if [ $inputs_found -eq 0 ]; then - inputs=$(echo -ne "$line" | awk '{print $2}') - if [[ "$inputs" == "to" ]]; then - continue - fi - inputs_found=1 - else - if [[ "${line:0:6}" == "index:" ]]; then - current_index="${line:7}" - elif [[ "${line:0:25}" == "application.process.id = " ]]; then - if [[ "${line:25}" == "\"$process_id\"" ]]; then - # index found... - break; - fi - fi + if [ -z "$sink_input_index" ]; then + echo "Could not find sink input index for '$1' (PID: $process_id)." + exit 1 fi -done < $temp -rm -f $temp - -if [ $current_index -eq -1 ]; then - echo "Could not find "$1" in the processes that output sound." - exit 1 -fi - -# muting... -if [[ "$2" == "mute" ]]; then - pacmd set-sink-input-mute "$current_index" 1 > /dev/null 2>&1 -else - pacmd set-sink-input-mute "$current_index" 0 > /dev/null 2>&1 -fi + # Perform the specified action + if [ "$2" == "mute" ]; then + pacmd set-sink-input-mute "$sink_input_index" 1 > /dev/null 2>&1 + elif [ "$2" == "unmute" ]; then + pacmd set-sink-input-mute "$sink_input_index" 0 > /dev/null 2>&1 + elif [ "$2" == "respawn" ]; then + kill "$process_id" # kill application + while pgrep -x "$1" >/dev/null; do sleep 1; done # wait for application to die + "$1" & # start application + fi +done exit 0 diff --git a/mute_spotify_timer.sh b/mute_spotify_timer.sh index 1e94d29..0b00ceb 100755 --- a/mute_spotify_timer.sh +++ b/mute_spotify_timer.sh @@ -1,17 +1,23 @@ #!/bin/bash +respawn=false # set whether to mute or restart spotify to skip ads + while true; do # get Spotify playing song name name=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | sed -n '/title/{n;p}' | cut -d '"' -f 2` url=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | sed -n '/url/{n;p}' | cut -d '"' -f 2` echo $name - - if [[ "$name" = *"Advertisement"* || "$name" = *"Spotify"* ]] || [[ $url == *"/ad/"* ]]; then + # if song name contains "Advertisement" or "Spotify" or url contains "/ad/" + if [[ "$name" = *"Advertisement"* || "$name" = *"Spotify"* ]] || [[ $url == *"/ad/"* ]]; then echo "Muting" - ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute + ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute + if [[ $respawn == true ]]; then + echo "Respawning" + ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify respawn + fi else echo "Unmuting" - ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute + ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute fi sleep 1 done From 3e3a65641b10554b06c7abe26b940e4e35cef2c9 Mon Sep 17 00:00:00 2001 From: smarkoco Date: Tue, 27 Feb 2024 15:52:15 -0500 Subject: [PATCH 2/7] remove "git/" from path --- adfree.sh | 2 +- adfree_app.sh.bak | 80 +++++++++++++++++++++++++++++++++++++++++++ mute_spotify_timer.sh | 6 ++-- 3 files changed, 84 insertions(+), 4 deletions(-) create mode 100755 adfree_app.sh.bak diff --git a/adfree.sh b/adfree.sh index c060a84..82d3ca5 100755 --- a/adfree.sh +++ b/adfree.sh @@ -1,3 +1,3 @@ #!/bin/bash tmux new-session -d -s adfree -tmux send-keys "~/git/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh $respawn" C-m +tmux send-keys "~/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh $respawn" C-m \ No newline at end of file diff --git a/adfree_app.sh.bak b/adfree_app.sh.bak new file mode 100755 index 0000000..0ed2054 --- /dev/null +++ b/adfree_app.sh.bak @@ -0,0 +1,80 @@ +#!/bin/bash +# Script to respawn or mute an application using PulseAudio, depending solely on +# process name, constructed as answer on askubuntu.com:. +# http://askubuntu.com/questions/180612/script-to-mute-an-application + +# It works as: mute_application.sh vlc mute OR mute_application.sh vlc unmute + +if [ -z "$1" ]; then + echo "Please provide me with an application name" + exit 1 +fi + +if [ -z "$2" ]; then + echo "Please provide me with an action mute/unmute/respawn after the application name" + exit 1 +fi + +if ! [[ "$2" == "mute" || "$2" == "unmute" || "$2" == "respawn" ]]; then + echo "The 2nd argument must be mute/unmute/respawn" + exit 1 +fi + +process_id=$(pidof "$1") + +if [ $? -ne 0 ]; then + echo "There is no such process as "$1"" + exit 1 +fi + +temp=$(mktemp) + +pacmd list-sink-inputs > $temp + +inputs_found=0; +current_index=-1; + +while read line; do + if [ $inputs_found -eq 0 ]; then + inputs=$(echo -ne "$line" | awk '{print $2}') + if [[ "$inputs" == "to" ]]; then + continue + fi + inputs_found=1 + else + if [[ "${line:0:6}" == "index:" ]]; then + current_index="${line:7}" + elif [[ "${line:0:25}" == "application.process.id = " ]]; then + if [[ "${line:25}" == "\"$process_id\"" ]]; then + # index found... + break; + fi + fi + fi +done < $temp + +rm -f $temp + +if [ $current_index -eq -1 ]; then + echo "Could not find "$1" in the processes that output sound." + exit 1 +fi + +# muting, unmuting, or respawning +if [[ "$2" == "mute" ]]; then + pacmd set-sink-input-mute "$current_index" 1 > /dev/null 2>&1 +elif [[ "$2" == "unmute" ]]; then + pacmd set-sink-input-mute "$current_index" 0 > /dev/null 2>&1 +elif [[ "$2" == "respawn" ]]; then + killall $1 # kill application + while pgrep -x application >/dev/null; do sleep 1; done # wait for application to die + $1 # start application + if [[ "$1" == "spotify" ]]; then + echo "Waiting for Spotify to start..." + sleep 8 # wait for application to start + echo "Spotify started, playing song..." + xdotool search --name "$1" key space # send spacebar to application window to play song + echo "Play signal sent to Spotify" + fi +fi +exit 0 diff --git a/mute_spotify_timer.sh b/mute_spotify_timer.sh index 0b00ceb..d556df9 100755 --- a/mute_spotify_timer.sh +++ b/mute_spotify_timer.sh @@ -10,14 +10,14 @@ while true; do # if song name contains "Advertisement" or "Spotify" or url contains "/ad/" if [[ "$name" = *"Advertisement"* || "$name" = *"Spotify"* ]] || [[ $url == *"/ad/"* ]]; then echo "Muting" - ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute + ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute if [[ $respawn == true ]]; then echo "Respawning" - ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify respawn + ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify respawn fi else echo "Unmuting" - ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute + ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute fi sleep 1 done From 082c7f7eb3d3dc5a13ba4b0d49a300b9081f07f0 Mon Sep 17 00:00:00 2001 From: smarkoco Date: Tue, 27 Feb 2024 16:00:15 -0500 Subject: [PATCH 3/7] remove typo in adfree.sh --- adfree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adfree.sh b/adfree.sh index 82d3ca5..7980b9a 100755 --- a/adfree.sh +++ b/adfree.sh @@ -1,3 +1,3 @@ #!/bin/bash tmux new-session -d -s adfree -tmux send-keys "~/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh $respawn" C-m \ No newline at end of file +tmux send-keys "~/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh" C-m \ No newline at end of file From 34e1dd7b893ae1a7dad5e7ecf8dee2536809c2dc Mon Sep 17 00:00:00 2001 From: smarkoco <53878603+smarkoco@users.noreply.github.com> Date: Thu, 29 Feb 2024 12:00:17 -0500 Subject: [PATCH 4/7] Delete adfree_app.sh.bak --- adfree_app.sh.bak | 80 ----------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100755 adfree_app.sh.bak diff --git a/adfree_app.sh.bak b/adfree_app.sh.bak deleted file mode 100755 index 0ed2054..0000000 --- a/adfree_app.sh.bak +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash -# Script to respawn or mute an application using PulseAudio, depending solely on -# process name, constructed as answer on askubuntu.com:. -# http://askubuntu.com/questions/180612/script-to-mute-an-application - -# It works as: mute_application.sh vlc mute OR mute_application.sh vlc unmute - -if [ -z "$1" ]; then - echo "Please provide me with an application name" - exit 1 -fi - -if [ -z "$2" ]; then - echo "Please provide me with an action mute/unmute/respawn after the application name" - exit 1 -fi - -if ! [[ "$2" == "mute" || "$2" == "unmute" || "$2" == "respawn" ]]; then - echo "The 2nd argument must be mute/unmute/respawn" - exit 1 -fi - -process_id=$(pidof "$1") - -if [ $? -ne 0 ]; then - echo "There is no such process as "$1"" - exit 1 -fi - -temp=$(mktemp) - -pacmd list-sink-inputs > $temp - -inputs_found=0; -current_index=-1; - -while read line; do - if [ $inputs_found -eq 0 ]; then - inputs=$(echo -ne "$line" | awk '{print $2}') - if [[ "$inputs" == "to" ]]; then - continue - fi - inputs_found=1 - else - if [[ "${line:0:6}" == "index:" ]]; then - current_index="${line:7}" - elif [[ "${line:0:25}" == "application.process.id = " ]]; then - if [[ "${line:25}" == "\"$process_id\"" ]]; then - # index found... - break; - fi - fi - fi -done < $temp - -rm -f $temp - -if [ $current_index -eq -1 ]; then - echo "Could not find "$1" in the processes that output sound." - exit 1 -fi - -# muting, unmuting, or respawning -if [[ "$2" == "mute" ]]; then - pacmd set-sink-input-mute "$current_index" 1 > /dev/null 2>&1 -elif [[ "$2" == "unmute" ]]; then - pacmd set-sink-input-mute "$current_index" 0 > /dev/null 2>&1 -elif [[ "$2" == "respawn" ]]; then - killall $1 # kill application - while pgrep -x application >/dev/null; do sleep 1; done # wait for application to die - $1 # start application - if [[ "$1" == "spotify" ]]; then - echo "Waiting for Spotify to start..." - sleep 8 # wait for application to start - echo "Spotify started, playing song..." - xdotool search --name "$1" key space # send spacebar to application window to play song - echo "Play signal sent to Spotify" - fi -fi -exit 0 From 2fecf113f6627efb1f041aeabebf815487ef28f6 Mon Sep 17 00:00:00 2001 From: smarkoco Date: Thu, 29 Feb 2024 15:32:28 -0500 Subject: [PATCH 5/7] only use matching pacmd sink to mute, not proc IDs --- adfree.sh | 2 +- mute_app.sh | 45 +++++++++++++++++++------------------------ mute_spotify_timer.sh | 6 +++--- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/adfree.sh b/adfree.sh index 7980b9a..b5b095b 100755 --- a/adfree.sh +++ b/adfree.sh @@ -1,3 +1,3 @@ #!/bin/bash tmux new-session -d -s adfree -tmux send-keys "~/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh" C-m \ No newline at end of file +tmux send-keys "~/git/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh" C-m \ No newline at end of file diff --git a/mute_app.sh b/mute_app.sh index d2fa20e..7a5bdf9 100755 --- a/mute_app.sh +++ b/mute_app.sh @@ -17,34 +17,29 @@ if [[ "$2" != "mute" && "$2" != "unmute" && "$2" != "respawn" ]]; then exit 1 fi -# Get the process ID associated with the specified application -process_ids=$(pgrep -d ' ' -x "$1") +# Get the sink input index for the sink with matching application name +sink_input_index=$(pacmd list-sink-inputs | grep -B 20 -P "application.name = \"${1}\"" | grep "index" | awk '{print $2}') -if [ -z "$process_ids" ]; then - echo "There is no such process matching: '$1'." +if [ -z "$sink_input_index" ]; then + echo "Could not find sink input index for $1." exit 1 fi -# Loop through each process ID -for process_id in $process_ids; do - # Get the sink input index for the sink with "spotify" in the name - sink_input_index=$(pacmd list-sink-inputs | grep -B 20 -P "application.name = \"${1}\"" | grep "index" | awk '{print $2}') - - if [ -z "$sink_input_index" ]; then - echo "Could not find sink input index for '$1' (PID: $process_id)." - exit 1 - fi - - # Perform the specified action - if [ "$2" == "mute" ]; then - pacmd set-sink-input-mute "$sink_input_index" 1 > /dev/null 2>&1 - elif [ "$2" == "unmute" ]; then - pacmd set-sink-input-mute "$sink_input_index" 0 > /dev/null 2>&1 - elif [ "$2" == "respawn" ]; then - kill "$process_id" # kill application - while pgrep -x "$1" >/dev/null; do sleep 1; done # wait for application to die - "$1" & # start application - fi -done +# Perform the specified action +if [ "$2" == "mute" ]; then + pacmd set-sink-input-mute "$sink_input_index" 1 > /dev/null 2>&1 + echo "Muted $1." +elif [ "$2" == "unmute" ]; then + pacmd set-sink-input-mute "$sink_input_index" 0 > /dev/null 2>&1 + echo "Unmuted $1." +elif [ "$2" == "respawn" ]; then + # Kill the application + pkill -x "$1" + # Wait for the application to close + while pgrep -x "$1" > /dev/null; do sleep 1; done + # Restart the application + "$1" > /dev/null 2>&1 & + echo "Respawned $1." +fi exit 0 diff --git a/mute_spotify_timer.sh b/mute_spotify_timer.sh index d556df9..0b00ceb 100755 --- a/mute_spotify_timer.sh +++ b/mute_spotify_timer.sh @@ -10,14 +10,14 @@ while true; do # if song name contains "Advertisement" or "Spotify" or url contains "/ad/" if [[ "$name" = *"Advertisement"* || "$name" = *"Spotify"* ]] || [[ $url == *"/ad/"* ]]; then echo "Muting" - ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute + ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute if [[ $respawn == true ]]; then echo "Respawning" - ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify respawn + ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify respawn fi else echo "Unmuting" - ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute + ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute fi sleep 1 done From 84cdee83f97fa84491b03a5860d819d2b1e1a124 Mon Sep 17 00:00:00 2001 From: smarkoco Date: Thu, 29 Feb 2024 16:25:21 -0500 Subject: [PATCH 6/7] critical: now loop to mute all spotify sinks --- adfree.sh | 2 +- mute_app.sh | 42 +++++++++++++++++++++++------------------- mute_spotify_timer.sh | 6 +++--- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/adfree.sh b/adfree.sh index b5b095b..7980b9a 100755 --- a/adfree.sh +++ b/adfree.sh @@ -1,3 +1,3 @@ #!/bin/bash tmux new-session -d -s adfree -tmux send-keys "~/git/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh" C-m \ No newline at end of file +tmux send-keys "~/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh" C-m \ No newline at end of file diff --git a/mute_app.sh b/mute_app.sh index 7a5bdf9..1990797 100755 --- a/mute_app.sh +++ b/mute_app.sh @@ -17,29 +17,33 @@ if [[ "$2" != "mute" && "$2" != "unmute" && "$2" != "respawn" ]]; then exit 1 fi -# Get the sink input index for the sink with matching application name -sink_input_index=$(pacmd list-sink-inputs | grep -B 20 -P "application.name = \"${1}\"" | grep "index" | awk '{print $2}') +# Get the sink input index for the sink with matching application name, and use grep to find all matching indexes +sink_input_indexes=$(pacmd list-sink-inputs | grep -B 20 "application.name = \"$1\"" | awk '/index:/{print $2}') -if [ -z "$sink_input_index" ]; then +if [ -z "$sink_input_indexes" ]; then echo "Could not find sink input index for $1." exit 1 fi -# Perform the specified action -if [ "$2" == "mute" ]; then - pacmd set-sink-input-mute "$sink_input_index" 1 > /dev/null 2>&1 - echo "Muted $1." -elif [ "$2" == "unmute" ]; then - pacmd set-sink-input-mute "$sink_input_index" 0 > /dev/null 2>&1 - echo "Unmuted $1." -elif [ "$2" == "respawn" ]; then - # Kill the application - pkill -x "$1" - # Wait for the application to close - while pgrep -x "$1" > /dev/null; do sleep 1; done - # Restart the application - "$1" > /dev/null 2>&1 & - echo "Respawned $1." -fi +# Perform the specified action on each sink input index +for sink_input_index in $sink_input_indexes; do + if [ "$2" == "mute" ]; then + pacmd set-sink-input-mute "$sink_input_index" 1 > /dev/null 2>&1 + echo "Muted $1 on sink input index $sink_input_index." + elif [ "$2" == "unmute" ]; then + pacmd set-sink-input-mute "$sink_input_index" 0 > /dev/null 2>&1 + echo "Unmuted $1 on sink input index $sink_input_index." + elif [ "$2" == "respawn" ]; then + # Kill the application + pkill -x "$1" + # Wait for the application to close + while pgrep -x "$1" > /dev/null; do sleep 1; done + # Restart the application + "$1" > /dev/null 2>&1 & + echo "Respawned $1." + # break out of the loop after respawning the application because this is only needed once + break + fi +done exit 0 diff --git a/mute_spotify_timer.sh b/mute_spotify_timer.sh index 0b00ceb..d556df9 100755 --- a/mute_spotify_timer.sh +++ b/mute_spotify_timer.sh @@ -10,14 +10,14 @@ while true; do # if song name contains "Advertisement" or "Spotify" or url contains "/ad/" if [[ "$name" = *"Advertisement"* || "$name" = *"Spotify"* ]] || [[ $url == *"/ad/"* ]]; then echo "Muting" - ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute + ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute if [[ $respawn == true ]]; then echo "Respawning" - ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify respawn + ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify respawn fi else echo "Unmuting" - ~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute + ~/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute fi sleep 1 done From 911dceb118372dcd628508897bb011aafb3d1a51 Mon Sep 17 00:00:00 2001 From: smarkoco Date: Fri, 22 Mar 2024 16:06:27 -0400 Subject: [PATCH 7/7] find spotify audio sinks more reliably --- mute_app.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mute_app.sh b/mute_app.sh index 1990797..44fba41 100755 --- a/mute_app.sh +++ b/mute_app.sh @@ -19,6 +19,10 @@ fi # Get the sink input index for the sink with matching application name, and use grep to find all matching indexes sink_input_indexes=$(pacmd list-sink-inputs | grep -B 20 "application.name = \"$1\"" | awk '/index:/{print $2}') +# this second command catches Chromium commercials +sink_input_indexes_alt=$(pacmd list-sink-inputs | grep -B 27 "application.process.binary = \"$1\"" | awk '/index:/{print $2}') +# Now combine the sink input indexes from both commands to remove duplicates +sink_input_indexes=$(echo -e "$sink_input_indexes\n$sink_input_indexes_alt" | sort -n | uniq) if [ -z "$sink_input_indexes" ]; then echo "Could not find sink input index for $1."