Skip to main content
Jamf Nation, hosted by Jamf, is a knowledgeable community of Apple-focused admins and Jamf users. Join us in person at the ninth annual Jamf Nation User Conference (JNUC) this November for three days of learning, laughter and IT love.

Script actions visible to end user

I have one machine where the end user can see the script unfold in front of their eyes.

Example. A Script that downloads the latest Google Chrome DMG, opens the DMG and copies it to the Application folder.

On 67 MacBooks it does that without the user seeing anything but on this 1 mac, it mounts the dmg, opens the Google Chrome window in the finder, copies, closes and quits.

Does anyone have any suggestions about what might be happening here?

Like Comment
Order by:
SOLVED Posted: by oliverr

The script should use this to mount the .dmg silently:
hdiutil attach /path/to/dmg -nobrowse

I can’t say why the other machines are behaving differently but if you post the full script we can get a better idea.

Like
SOLVED Posted: by vanschip-gerard

Hi @oliverr I have this with all scripts and it seems random. Some machines throw up blank DMG windows and nothing gets installed, others work fine. All deployed the same way.

This is the script I have for Slack:

#!/bin/bash -v

#if you want slack to quit - in use with a jamf notifcation policy unhash next line
#pkill Slack*

#gets current logged in user
consoleuser=$(ls -l /dev/console | cut -d " " -f4)

APP_NAME="Slack.app"
APP_PATH="/Applications/$APP_NAME"
APP_VERSION_KEY="CFBundleShortVersionString"


DOWNLOAD_URL="https://slack.com/ssb/download-osx"
finalDownloadUrl=$(curl "$DOWNLOAD_URL" -s -L -I -o /dev/null -w '%{url_effective}')
dmgName=$(printf "%s" "${finalDownloadUrl[@]}" | sed 's@.*/@@')
slackDmgPath="/tmp/$dmgName"

################################

#find new version of Slack
currentSlackVersion=$(/usr/bin/curl -s 'https://downloads.slack-edge.com/mac_releases/releases.json' | grep -o "[0-9]\.[0-9]\.[0-9]" | tail -1)

if [ -d "$APP_PATH" ]; then
    localSlackVersion=$(defaults read "$APP_PATH/Contents/Info.plist" "$APP_VERSION_KEY")
    if [ "$currentSlackVersion" = "$localSlackVersion" ]; then
        printf "Slack is already up-to-date. Version: %s" "$localSlackVersion"
        exit 0
    fi
fi

#find if slack is running
if pgrep '[S]lack'; then
    printf "Error: Slack is currently running!\n"
    exit 409
else

# Remove the existing Application
rm -rf /Applications/Slack.app

#downloads latest version of Slack
curl -L -o "$slackDmgPath" "$finalDownloadUrl"

#mount the .dmg
hdiutil attach -nobrowse $slackDmgPath

#Copy the update app into applications folder
sudo cp -R /Volumes/Slack*/Slack.app /Applications

#unmount and eject dmg
mountName=$(diskutil list | grep Slack | awk '{ print $3 }')
umount -f /Volumes/Slack*/
diskutil eject $mountName

#clean up /tmp download
rm -rf "$slackDmgPath"

# Slack permissions are really dumb
chown -R $consoleuser:admin "/Applications/Slack.app"

localSlackVersion=$(defaults read "$APP_PATH/Contents/Info.plist" "$APP_VERSION_KEY")
    if [ "$currentSlackVersion" = "$localSlackVersion" ]; then
        printf "Slack is now updated/installed. Version: %s" "$localSlackVersion"
    fi
fi

#slack will relaunch if it was previously running
if [ "$slackOn" == "" ] ; then
    exit 0
else
    su - "${consoleuser}" -c 'open -a /Applications/Slack.app'
fi

    exit 0
fi
Like
SOLVED Posted: by vanschip-gerard

And same with the Chrome script.

#!/bin/bash
#########################################################################################

# ABOUT THIS PROGRAM

NAME

GoogleChromeInstall.sh -- Installs the latest Google Chrome version

SYNOPSIS

sudo GoogleChromeInstall.sh

########################################################################################

# HISTORY

Version: 1.0

- Joe Farage, 17.03.2015

########################################################################################

Script to download and install Google Earth.

Only works on Intel systems.

Edits by Will Pierce April 24, 2015

########################################################################################

Var for jamfHelper

jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

Var for the icon

icon="/Applications/Google Chrome.app/Contents/Resources/app.icns"

Var for the date and time for use in script timing and display

the_date=date "%Y-%m-%d" the_time=date "%r"

Check to see if Google Chrome is installed, is is then update if not exit

if [ -e /Applications/Google\ Chrome.app ]; then # Kick off a jamfHelper message stating the GoogleChrome update "$jamfHelper" -windowType hud -title "$the_time" -icon "$icon" -heading "Google Chrome" -description "Checking for Chrome..." -timeout 5 >&- dmgfile="googlechrome.dmg" volname="Google Chrome" logfile="/Library/Logs/GoogleChromeInstallScript.log" url='https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg' # Are we running on Intel? if [ '/usr/bin/uname -p'="i386" -o '/usr/bin/uname -p'="x86_64" ]; then /bin/echo "--" >> ${logfile} /bin/echo "date: Downloading latest version." >> ${logfile} "$jamfHelper" -windowType hud -title "$the_time" -icon "$icon" -heading "Google Chrome" -description "Chrome found, Downloading latest version..." & /usr/bin/curl -s -o /tmp/${dmgfile} ${url} /bin/echo "date: Mounting installer disk image." >> ${logfile} /usr/bin/hdiutil attach /tmp/${dmgfile} -nobrowse -quiet /bin/echo "date: Installing..." >> ${logfile} killall jamfHelper wait 2>/dev/null "$jamfHelper" -windowType hud -title "$the_time" -icon "$icon" -heading "Google Chrome" -description "Installing latest version..." & ditto -rsrc "/Volumes/${volname}/Google Chrome.app" "/Applications/Google Chrome.app" /bin/sleep 10 /bin/echo "date: Unmounting installer disk image." >> ${logfile} /usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep "${volname}" | awk '{print $1}') -quiet /bin/sleep 10 /bin/echo "date: Deleting disk image." >> ${logfile} /bin/rm /tmp/"${dmgfile}" else /bin/echo "date: ERROR: This script is for Intel Macs only." >> ${logfile} fi # Kill the jamfHelper after the install killall jamfHelper wait 2>/dev/null # New jamfHelper message that we are done installing Chrome "$jamfHelper" -windowType hud -title "$the_time" -icon "$icon" -timeout 5 -heading "Google Chrome" -description "Checking for updates... DONE" -timeout 5 else echo "GoogleChrome not found." exit 0 fi exit 0
Like
SOLVED Posted: by Tonyliu2ca

try hdiutil with "-mountpoint path" option, where the "path" to a folder not in /Volumes, but for example in /tmp

Like