SCRIPT | Install-Slack-Latest

Install Slack

Summary

This script will install the latest Universal version of Google Chrome.


Script Content

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

# Update variables. These shouldn't need to change for each update
dmgname="Slack.dmg"
dmglink="https://slack.com/ssb/download-osx-universal"
apptoreplace="Slack.app"
apptoreplacerunningname="Slack"

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

# Mount DMG 
hdiutil mount -nobrowse $dmgname

#Slack DMG now has changing DMG name. Grab it on the fly as it's mounted
dmgmountedname=`ls /Volumes/ | grep "Slack"`

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

# Remove the app from the Applications Folder
rm -rf "/Applications/$apptoreplace"

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

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

chown -R ${netname}:Staff && chmod -R 755 "/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

Slack is pretty much an essential application for any user these days, this script allow you to know the latest version is always being deployed.

As this script installs the Universal version of Slack, it will natively run on Macs with either Intel (x86_64) or Apple Silicon (arm64) CPUs.