Skip to content

Instantly share code, notes, and snippets.

@glouel
Last active August 16, 2022 12:07
Show Gist options
  • Save glouel/48a5f7cbff32a8764779477fcc040d06 to your computer and use it in GitHub Desktop.
Save glouel/48a5f7cbff32a8764779477fcc040d06 to your computer and use it in GitHub Desktop.
JAMF Aerial install script (untested)
#!/bin/bash
URL='https://github.com/JohnCoates/Aerial/releases/latest/download'
FILE='Aerial.saver.zip'
APP_NAME='Aerial' # assuming it's a pretty name for jamf ui
APP_LOCATION="/Users/$CURRENT_USER/Library/Screen Savers/Aerial.saver"
APP_GREPPER_NAME='Aerial' # no idea what that is
### Check if installed or not
if [ -e $APP_LOCATION ]; then
INSTALLED_VERSION=$(defaults read "$APP_LOCATION/Contents/info" CFBundleShortVersionString)
echo "`date` | Installed version of $APP_NAME is $INSTALLED_VERSION at $APP_LOCATION"
else
echo "`date` | No current installation of $APP_NAME found as $APP_LOCATION"
fi
# Grab latest version
echo "`date` | Downloading zip $URL/$FILE"
TMP_LOCATION=/tmp/Aerial.saver.zip
/usr/bin/curl -Ls "${URL}/${FILE}" -o "$TMP_LOCATION"
if [ -e $TMP_LOCATION ]; then
echo "`date` | Downloaded $APP_NAME to $TMP_LOCATION"
else
echo "`date` | Could not find any downloads for $APP_NAME on $TMP_LOCATION"
exit 1
fi
# unzip the saver
unzip -v "$TMP_LOCATION" # you can remove -v to remove the debug stuff, or "tar xop " instead of unzip if your script runs very very early
TMP_SAVER=/tmp/Aerial.saver # this is the unzipped file
# just in case
if [ -e $TMP_LOCATION ]; then
echo "`date` | Unzipped $TMP_LOCATION to $TMP_SAVER"
else
echo "`date` | Unzip failed for $APP_NAME on $TMP_LOCATION"
exit 1
fi
echo "`date` | Removing old version of $APP_NAME at $APP_LOCATION"
rm -rf $APP_LOCATION
echo "`date` | Moving $TMP_SAVER to /Users/$CURRENT_USER/Library/Screen\ Savers/."
mv $TMP_SAVER /Users/$CURRENT_USER/Library/Screen\ Savers/
chown $CURRENT_USER /Users/$CURRENT_USER/Library/Screen\ Savers/Aerial.saver
echo "`date` | Deleting zip file for $APP_NAME"
rm $TMP_LOCATION
# Display the screensaver version installed, this works too for .saver ;)
INSTALLED_VERSION=$(defaults read "$APP_LOCATION/Contents/info" CFBundleShortVersionString)
echo "`date` | Successfully installed $APP_NAME with version $INSTALLED_VERSION"
##### if you stop here, you can run that upper part, maybe monthly, to update to the latest Aerial
##### on first install you can do the extra stuff below
# This is a great idea as macOS sometimes does not create that folder
echo "`date` | Creating empty folder /Users/$CURRENT_USER/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Library/Application\ Support/Aerial/ for cache"
mkdir -p /Users/$CURRENT_USER/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Library/Application\ Support/Aerial
echo "`date` | Added settings for $APP_NAME"
# adapted from https://support.carouselsignage.com/hc/en-us/articles/360047317971-Jamf-Setup-macOS-Screen-Saver-for-Carousel-Cloud
huuid=$(system_profiler SPHardwareDataType | awk '/Hardware UUID/ {print $3}')
ssPlist="/Users/$CURRENT_USER/Library/Preferences/ByHost/com.apple.screensaver.$huuid.plist"
screenSaverFileName="Aerial.saver"
screenSaverPath="/Users/$CURRENT_USER/Library/Screen Savers"
mkdir -p "/Users/$CURRENT_USER/Library/Preferences/ByHost"
#mkdir -p "/Users/$CURRENT_USER/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Library/Preferences/ByHost"
mkdir -p "$screenSaverPath"
# set the screen saver for the current user to the one we installed
echo "`date` | Adding settings for $CURRENT_USER"
/usr/libexec/PlistBuddy -c "Print moduleDict" $ssPlist
if [ $? -eq 1 ]; then
/usr/libexec/PlistBuddy -c "Add :moduleDict dict" $ssPlist
fi
/usr/libexec/PlistBuddy -c "Print moduleDict:moduleName" $ssPlist
if [ $? -eq 1 ]; then
/usr/libexec/PlistBuddy -c "Add :moduleDict:moduleName string Aerial" $ssPlist
else
/usr/libexec/PlistBuddy -c "Set :moduleDict:moduleName Aerial" $ssPlist
fi
/usr/libexec/PlistBuddy -c "Print moduleDict:path" $ssPlist
if [ $? -eq 1 ]; then
/usr/libexec/PlistBuddy -c "Add :moduleDict:path string $screenSaverPath/$screenSaverFileName" $ssPlist
else
/usr/libexec/PlistBuddy -c "Set :moduleDict:path $screenSaverPath/$screenSaverFileName" $ssPlist
fi
/usr/libexec/PlistBuddy -c "Print showClock" $ssPlist
if [ $? -eq 1 ]; then
/usr/libexec/PlistBuddy -c "Add showClock string NO" $ssPlist
else
/usr/libexec/PlistBuddy -c "Set showClock NO" $ssPlist
fi
/usr/libexec/PlistBuddy -c "Print idleTime" $ssPlist
if [ $? -eq 1 ]; then
# 300 seconds = 5 minutes
/usr/libexec/PlistBuddy -c "Add idleTime int 300" $ssPlist
else
/usr/libexec/PlistBuddy -c "Set idleTime 300" $ssPlist
fi
/usr/libexec/PlistBuddy -c "Print CleanExit" $ssPlist
if [ $? -eq 1 ]; then
# 300 seconds = 5 minutes
/usr/libexec/PlistBuddy -c "Add CleanExit string YES" $ssPlist
else
/usr/libexec/PlistBuddy -c "Set CleanExit YES" $ssPlist
fi
chown $CURRENT_USER "$ssPlist"
killall cfprefsd
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment