Skip to content

Instantly share code, notes, and snippets.

@jetfir3
Last active May 7, 2024 01:21
Show Gist options
  • Save jetfir3/f620e44fc246c1bed45ed040bbfa2d68 to your computer and use it in GitHub Desktop.
Save jetfir3/f620e44fc246c1bed45ed040bbfa2d68 to your computer and use it in GitHub Desktop.
Uninstallify -- remove Spotify + app/cache data
#!/usr/bin/env bash
# Uninstallify -- remove Spotify + app/cache data
case $(uname | tr '[:upper:]' '[:lower:]') in
darwin*) platformType='macOS' ;;
*) platformType='Linux' ;;
esac
command pgrep [sS]potify 2>/dev/null | xargs kill -9 2>/dev/null
search_apppath_linux () {
local timeout=6
local paths=("/opt" "/usr/share" "/var/lib/flatpak" "$HOME/.local/share" "/")
for path in "${paths[@]}"; do
local path="${path}"
local timeLimit=$(($(date +%s) + timeout))
while (( $(date +%s) < "${timeLimit}" )); do
appPath=$(find "${path}" -type f -path "*/spotify*Apps/*" \( -name "xpui.spa" -o -name "xpui.bak" \) -size +3M -print -quit 2>/dev/null | grep -v "snap" | rev | cut -d/ -f3- | rev)
[[ -n "${appPath}" ]] && return 0
pgrep -x find > /dev/null || break
sleep 1
done
done
return 1
}
search_cachepath_linux () {
local timeout=6
local paths=("$HOME/.cache" "$HOME/.var/app" "/var/lib/flatpak/" "$HOME" "/")
for path in "${paths[@]}"; do
local path="${path}"
local timeLimit=$(($(date +%s) + timeout))
while (( $(date +%s) < "${timeLimit}" )); do
appCachePath=$(find "${path}" -type d -path "*cache/spotify*" -print -quit 2>/dev/null)
[[ -n "${appCachePath}" ]] && return 0
pgrep -x find > /dev/null || break
sleep 1
done
done
return 1
}
search_appdatapath_linux () {
local timeout=6
local paths=("$HOME/.config" "$HOME/.var/app" "/var/lib/flatpak/" "$HOME" "/")
for path in "${paths[@]}"; do
local path="${path}"
local timeLimit=$(($(date +%s) + timeout))
while (( $(date +%s) < "${timeLimit}" )); do
appDataPath=$(find "${path}" -type f -path "*/spotify/prefs" -print -quit 2>/dev/null | rev | cut -d/ -f2- | rev)
[[ -n "${appDataPath}" ]] && return 0
pgrep -x find > /dev/null || break
sleep 1
done
done
return 1
}
delete_path () {
local path=$1
local pathName=$2
[[ ! -d "${path}" ]] && echo "${pathName} not found" >&2 && return
read -p "Are you sure you want to delete ${path}? (y/n) " -n 1 -r
echo
[[ ! $REPLY =~ ^[Yy]$ ]] && { echo "${pathName} at ${path} not deleted"; return; }
rm -rf "${path}" 2>/dev/null
[[ $? -eq 0 ]] && { echo "${pathName} at ${path} deleted"; return; }
sudo rm -rf "${path}" 2>/dev/null
if [[ $? -eq 0 ]]; then
echo "${pathName} at ${path} deleted with elevated privileges"
elif [[ -d "${path}" ]]; then
echo "${pathName} at ${path} not deleted"
else
echo "${pathName} at ${path} not found"
fi
}
if [[ "${platformType}" == "Linux" ]]; then
echo "Searching for app path..."; search_apppath_linux
echo "Searching for app cache path..."; search_cachepath_linux
echo "Searching for app data path..."; search_appdatapath_linux
fi
if [[ "${platformType}" == "macOS" ]]; then
appPath="/Applications/Spotify.app"
[[ -d "${HOME}${appPath}" ]] && appPath="${HOME}/Applications/Spotify.app"
appDataPath="${HOME}/Library/Application Support/Spotify"
appCachePath="${HOME}/Library/Caches/com.spotify.client"
fi
delete_path "${appPath}" "App"
delete_path "${appCachePath}" "App cache"
delete_path "${appDataPath}" "App data"
echo -e "\nFinished!"
exit 0
@jetfir3
Copy link
Author

jetfir3 commented Nov 21, 2023

  • Run script to completely uninstall Spotify on Linux and macOS
  • If found, script will ask before deleting app, app data, cache data

Run directly with:

bash <(curl -sSL https://gist.github.com/jetfir3/f620e44fc246c1bed45ed040bbfa2d68/raw/uninstallify.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment