SCRIPT | Install-Spotify-Latest

Install Spotify

Summary

This script will install the latest version of Spotify.


Script Content

#!/bin/zsh
cd "/Library/Application Support/JAMF/tmp"

# Update variables. These shouldn't need to change for each update
dmgname="Spotify.dmg"
dmglink="https://download.scdn.co/Spotify.dmg"
dmgmountedname="Spotify"
apptoreplace="Spotify.app"
apptoreplacerunningname="Spotify"

# Download DMG
curl -L -o $dmgname "$dmglink"

# Mount DMG 
hdiutil mount -nobrowse $dmgname

# Kill the app if it is running
killall -Kill "$apptoreplacerunningname"

# Set the user as the current logged in user
netname=`ls -l /dev/console | cut -d " " -f 4`

# Remove the app from the Applications Folder
rm -rf "/Applications/$apptoreplace"
rm -rf "/Users/${netname}/Applications/$apptoreplace"
rm -rf "/Applications/Spotify (old).app"

# Copy the new version into the Applications Folder
cp -R "/Volumes/$dmgmountedname/$apptoreplace" /Applications

chown -R ${netname}:Staff "/Applications/$apptoreplace"

sudo xattr -rc "/Applications/$apptoreplace/"

# Unmount the DMG
hdiutil unmount "/Volumes/$dmgmountedname"

# Remove the downloaded DMG
rm $dmgname

# Clear out the used variables
unset dmgname
unset dmglink
unset dmgmountedname
unset apptoreplace
unset apptoreplacerunningname
unset netname
exit 0

Concluding Comments

This script installs the latest version of the Spotify application… one of the worlds most popular music streaming services.