Forked from fatihkaan22/spotify-kill-pulse-client.sh
Created
January 27, 2022 14:14
-
-
Save undg/77e4da678ebeec7ab7d628028ba3b47f to your computer and use it in GitHub Desktop.
Kills unused spotify pulseaudio instances
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 | |
spotifyInstances=() | |
while read LINE1; read LINE2; do | |
IFS=':-=' | |
read -ra L1 <<< $LINE1 | |
read -ra L2 <<< $LINE2 | |
# trim leading/trailing spaces for error checking | |
INDEX_STR=$(echo "${L1[0]}" | xargs) | |
NAME_STR=$(echo "${L2[0]}" | xargs) | |
if [[ $INDEX_STR != 'index' || $NAME_STR != 'application.name' ]]; then | |
echo 'ERROR' | |
exit | |
fi | |
INDEX=${L1[1]} | |
NAME=${L2[1]} | |
if [[ $NAME == ' "Spotify"' ]]; then | |
spotifyInstances+=( $INDEX ) | |
fi | |
done < <(pacmd list-clients | grep -e 'index:' -e 'application.name') | |
# remove last element (active client) | |
unset 'spotifyInstances[${#arr[@]}-1]' | |
for s in ${spotifyInstances[@]}; do | |
echo "pacmd kill-client $s" | |
pacmd kill-client $s | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment