SCRIPT | Management-Rename-Mac

Rename Macs

Summary

This script will enforce naming Macs based upon their serial numbers.

In addition to using the serial number to form the bulk of the naming convention, the script will also determine wether a laptop or desktop Mac is being renamed. If the computer being renamed is a laptop then the serial number will be prefixed with “ML-” representing “Mac Laptop“. If the computer is determined to be a desktop computer then the serial number will be prefixed with “MD-” to signify “Mac Desktop“.


Script Content

#!/bin/zsh

islaptop=`/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | grep "Book"`

if [ "$islaptop" != "" ]; then
    newmacname=`system_profiler SPHardwareDataType | grep "Serial Number (system)" | sed 's/Serial Number (system): /ML-/'`
else    
    newmacname=`system_profiler SPHardwareDataType | grep "Serial Number (system)" | sed 's/Serial Number (system): /MD-/'`
fi

scutil --set ComputerName $newmacname
scutil --set HostName $newmacname
scutil --set LocalHostName $newmacname
defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName $newmacname
rm -f "$islaptop"
rm -f "$newmacname"

Concluding Comments

By implementing this naming convention when working with a large number of Macs will ensure that all computer names are unique. In addition it will allow for easy identification of wether a Mac is a laptop or desktop model.

SCRIPT | Install-Microsoft-VisualStudioCode-Latest

Install Microsoft Visual Studio Code

Summary

This script downloads the latest version of Visual Studio Code from the internet then installs the application. If the application is already installed, the previous version is removed prior to installing.


Script Content

#!/bin/zsh
############################################################
#
# ABOUT THIS PROGRAM
#
# 	Downloads the latest version of Visual Studio Code from the internet then installs the
#	application. If the application is already installed, then previous version is removed
#	prior to installing.
#
#	Modified base script taken from:
#	https://www.jamf.com/jamf-nation/third-party-products/files/1035/auto-install-visual-studio-code
#
############################################################

# Script to download and install VS Code directly from the Internet

		# Assignment of global variables
		protocolDomain='https://code.visualstudio.com'
		zipfile="VSCode-darwin.zip"
		logfile="/Library/Logs/VSCodeInstallScript.log"

		# Begin writing to a log file
		/bin/echo "--" >> ${logfile}
		/bin/echo "Parsing through $protocolDomain in order to find the download URL for VSCode." >> ${logfile}

		# Find the release page for the new update
		newUpdatePage=$(curl $protocolDomain/updates)

		# Remove the redirection clause in order to obtain the URL for the new update page
		redirectClause='Found. Redirecting to '
		newUpdatePage=${newUpdatePage#${redirectClause}}

		# Find the download page for the specific new update and revision (NOTE: The download for the Linux URL is very similar to the Mac URL, and is therefore parsed from this page)
		linuxPath='/linux-x64/stable'
		linuxURL=$(curl $protocolDomain/$newUpdatePage | sed -n 's/.*href="\([^"]*\).*/\1/p' | grep "$linuxPath")

		# Remove the path to the Linux download and replace it with the path to the Mac download
		latestUpdateURL=${linuxURL%${linuxPath}}
		macPath='/darwin/stable'
		macDownloadPage="$latestUpdateURL$macPath"

		# Curl the resulting download page. It redirects to the actual download URL for the zip file
		macDownloadURL=$(curl $macDownloadPage)
		url=${macDownloadURL#${redirectClause}}

		# Kill any open sessions of VSCode
		/bin/echo "Killing any open sessions of Visual Studio Code." >> ${logfile}
		osascript -e 'quit app "Code"'

		# Remove the previous version of VSCode
		/bin/echo "Removing the previous version of Visual Studio Code." >> ${logfile}
		rm -rf /Applications/Visual\ Studio\ Code.app

		# Download the latest version from the parsed url via 'curl'
		/bin/echo "`date`: Downloading latest version." >> ${logfile}
		/usr/bin/curl -s -o /tmp/${zipfile} ${url}

		# Unzip the compressed .app and move it to /Applications
		/bin/echo "Unzipping the compressed file of the latest version and moving it to /Applications." >> ${logfile}
		unzip /tmp/${zipfile} -d /Applications

		# Remove the leftover zip file from the /tmp cache
		/bin/echo "Removing the .zip file from /tmp." >> ${logfile}
		rm -f /tmp/${zipfile}

		# Change the permissions and owndership of the .app file in order to remove it from the 'Downloaded from Internet' quarantine
		/bin/echo "Removing new application from 'Downloaded from Internet' quarantine." >> ${logfile}
		chmod -R 755 /Applications/Visual\ Studio\ Code.app
		chown -R root:wheel /Applications/Visual\ Studio\ Code.app

exit 0

Concluding Comments

Visual Studio Code, also commonly referred to as VS Code, is a source-code editor made by Microsoft for Windows, Linux and macOS. Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git.

SCRIPT | Install-RoyalTSX-5.0.6.1000

Install Royal TSX

Summary

This script will install the version 5.0.6.1000 of Royal TSX.

Although the script installs a static version of Royal TSX (in this case 5.0.6.1000), the script can easily be modified for new versions as they become available simply be editing the version number in the variables for the “dmgname” and the “dmglink“.


Script Content

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

# Update variables
dmgname="royaltsx_5.0.6.1000.dmg"
dmglink="https://royaltsx-v5.royalapps.com/updates/royaltsx_5.0.6.1000.dmg"
dmgmountedname="Royal TSX"
apptoreplace="Royal TSX.app"
apptoreplacerunningname="RoyalTSX"

# Download DMG
curl -L -O "$dmglink"

# Convert DMG to CDR to bypass EULA and mount DMG 
hdiutil convert $dmgname -format UDTO -o $dmgname.cdr
hdiutil mount -nobrowse $dmgname.cdr

# 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 "/Applications/$apptoreplace"

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

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

# Remove the downloaded DMG
rm $dmgname
rm $dmgname.cdr

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

Concluding Comments

Royal TS is the only true cross-platform remote management solution available for Windows, macOS, iOS and Android. Documents created with Royal TS can be opened on all the supported platforms.

SCRIPT | Install-Zoom-Latest

Install Zoom

Summary

These scripts will install the latest version of Zoom.


Script Content

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

# Update variables. These shouldn't need to change for each update
pkgname="ZoomInstallerIT.pkg"
pkglink="https://zoom.us/client/latest/ZoomInstallerIT.pkg"
apptoupdaterunningname="zoom.us"

# Download PKG
curl -L -o "$pkgname" "$pkglink"

sleep 10

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

# Install PKG
sudo installer -pkg $pkgname -target /

# Remove the downloaded PKG
rm $pkgname

# Clear out the used variables
unset pkgname
unset pkglink
unset apptoupdaterunningname
exit 0

Concluding Comments

Zoom these days is pretty much the most essential video conferencing tool to have access to. This script will ensure users are always installing the latest version of the application.

SCRIPT | Install-Miro-Latest

Install Miro

Summary

These scripts will install the latest version of Miro.

Please note there is 2 versions of the script. One is for installing the arm64 version of the application intended for Macs with an Apple Silicon CPU, the other script installs the x86_64 version of the app for Macs with an Intel CPU.


Script Content (for Apple Silicon CPU Macs – arm64)

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

# Update variables. These shouldn't need to change for each update
dmgname="Miro.dmg"
dmglink="https://desktop.miro.com/platforms/darwin-arm64/Miro.dmg"
dmgmountedname="Miro"
apptoreplace="Miro.app"
apptoreplacerunningname="Miro"

# Download DMG
curl -L -O "$dmglink"

# Mount DMG 
hdiutil mount -nobrowse $dmgname

# 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

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
exit 0

Script Content (for Intel CPU Macs – x86_64)

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

# Update variables. These shouldn't need to change for each update
dmgname="Miro.dmg"
dmglink="https://desktop.miro.com/platforms/darwin/Miro.dmg"
dmgmountedname="Miro"
apptoreplace="Miro.app"
apptoreplacerunningname="Miro"

# Download DMG
curl -L -O "$dmglink"

# Mount DMG 
hdiutil mount -nobrowse $dmgname

# 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

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
exit 0

Concluding Comments

Miro is an online collaborative whiteboard platform that enables distributed teams to work effectively together, from brainstorming with digital sticky notes to planning and managing agile workflows.

SCRIPT | Install-TeamViewer-Latest

Install TeamViewer

Summary

This script will install the latest version of TeamViewer.


Script Content

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

# Update variables. These shouldn't need to change for each update
dmgname="TeamViewer.dmg"
dmglink="https://download.teamviewer.com/download/TeamViewer.dmg"
dmgmountedname="TeamViewer"
pkgname="Install TeamViewer.app/contents/Resources/Install TeamViewer.pkg"
apptoreplace="TeamViewer.app"
apptoreplacerunningname="TeamViewer"

# Download DMG
curl -L -O "$dmglink"

# Mount DMG 
hdiutil mount -nobrowse $dmgname

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

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

# Install the new version by running the .pkg file
installer -pkg "/Volumes/$dmgmountedname/$pkgname" -target /

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

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
unset pkgname
exit 0

Concluding Comments

TeamViewer is an essential tool when it comes to remote IT management and support, therefore it is essential to ensure the latest version is always installed to ensure the best usage experience. This script installs latest version.

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.

SCRIPT | Install-Skype-Latest

Install Microsoft Skype

Summary

This script will install the latest version of Microsoft Skype.


Script Content

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

# Update variables. These shouldn't need to change for each update
dmgname="getskype-macosx.dmg"
dmglink="http://www.skype.com/go/getskype-macosx.dmg"
dmgmountedname="Skype"
apptoreplace="Skype.app"
apptoreplacerunningname="Skype"

# Download DMG
curl -L -O "$dmglink"

# Mount DMG 
hdiutil mount -nobrowse $dmgname

# 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 "/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

Microsoft Teams is essential communication tool for many users, this script allows you to know the latest version is always being deployed.

SCRIPT | Install-Keka-Latest

Install Keka

Summary

This script will install the latest version of Keka.


Script Content

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

# Update variables. These shouldn't need to change for each update
dmgname="Keka.dmg"
#dmglink="http://download.kekaosx.com/"
dmglink="https://d.keka.io/"
dmgmountedname="Keka"
apptoreplace="Keka.app"
apptoreplacerunningname="Keka"

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

# Mount DMG 
hdiutil mount -nobrowse $dmgname

# 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 "/Applications/$apptoreplace"

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

# Unmount the DMG
sudo 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 will install the latest version of the Keka application for compressing and extracting files.

SCRIPT | Install-Google-Drive-Latest

Install Google Drive

Summary

This script will install the latest version of the Google Drive desktop application.


Script Content

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

# Update variables. These shouldn't need to change for each update
dmgname="googledrive.dmg"
dmglink="https://dl.google.com/drive-file-stream/googledrive.dmg"
dmgmountedname="Install Google Drive"
pkgname="GoogleDrive.pkg"
apptoreplace="Google Drive.app"
apptoreplacerunningname="Google Drive"

# Download DMG
curl -L -O "$dmglink"

# Mount DMG 
hdiutil mount -nobrowse $dmgname

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

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

# Install the new version by running the .pkg file
installer -pkg "/Volumes/$dmgmountedname/$pkgname" -target /

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

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

# User-enabled browser authentication for Google Drive
sudo -s -u $netname defaults write com.google.drivefs.settings ForceBrowserAuth -bool true

# 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 accounttype
unset pkgname
exit 0

Concluding Comments

The Google Drive desktop application makes sync’ing Google Drive contents to and from your Mac easier than ever.