Skip to content

Commit

Permalink
critical: now loop to mute all spotify sinks
Browse files Browse the repository at this point in the history
  • Loading branch information
smarkoco committed Feb 29, 2024
1 parent 2fecf11 commit 84cdee8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion adfree.sh
Original file line number Diff line number Diff line change
@@ -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
tmux send-keys "~/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh" C-m
42 changes: 23 additions & 19 deletions mute_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions mute_spotify_timer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 84cdee8

Please sign in to comment.