Spotify Bash Script for Improved Stability

Spotify on LinuxSo if you have used Spotify on Linux you will notice that there are often times where it will crash on start or act very broken after a launch and that seems to be primarily due to unwanted data being left in cache or config temps which seem to cause hangups.

Here is a special little bash script that makes Spotify work more smoothly and this especially makes the latest Beta with Spotify Apps work very nicely but can work in earlier versions as well:

#!/bin/bash
# Purge Spotify's ever horrible cache and temp config then run spotify
rm -Rf $HOME/.config/spotify && rm -Rf $HOME/.cache/spotify && spotify

For those who want to run this script as an application shortcut so it does tidying and then launches Spotify then simply do this from terminal:

1. nano spotify.sh

2. paste above code

3. chmod +x spotify.sh

4. Now sudo nano /usr/share/applications/spotify.desktop and paste this in but make sure to edit the “Exec” path to match the location of the Spotify.sh location on your system:

[Desktop Entry]
Name=Spotify
GenericName=Music Player
Comment=Listen to music using Spotify
Icon=spotify-linux-512×512
Exec=/home/bkerensa/bin/spotify.sh
TryExec=spotify
Terminal=false
Type=Application
Categories=Qt;Audio;Music;Player;AudioVideo
MimeType=x-scheme-handler/spotify

Now whenever you click the Spotify icon in the Unity launcher or whatever DE on Ubuntu you happen to be using it should execute the spotify.sh script which will tidy up and then run Spotify.

Hope this is useful for some!

 

 

 

Comments

  1. MatthewAguirre says

    But then you have to keep entering your credentials. I don’t have a problem if I leave the .config/spotify directory, only the .cache/spotify.

    Also, if you put a “spotify” script in your $HOME/bin directory which then executes /usr/bin/spotify, you don’t have to change any launchers since the $HOME/bin directory will be first in the PATH.

  2. Roger Dean says

    Many many thanks for this. I find that it works if I delete .cache/spotify but keep .config/spotify and then it remembers my login too…

  3. Roger Dean says

    Many many thanks for this. I find that it works if I delete .cache/spotify but keep .config/spotify and then it remembers my login too…