Scripting help: JamfHelper

Taylor_Armstron
Valued Contributor

Having issues with several packages, in particular Acrobat where users never seem to quit out. Working on a script to check for running app, upgrade if NOT running, present user with a notification if it is.

Have basic syntax down, but still running into issues. Anyone want to chime in on it and tell me what I'm missing? Have snippets taken from some of my other scripts and some from scripts found here on JamfNation, but missing something when sticking it all in together.

Basically, I'm caching the installer on all machines with a separate policy. Using a smart group detecting the cached installer, I then run the following script. It first checks to see if Acrobat is running. If NOT, proceeds to call a policy to install the cached package. If Acrobat IS running, asks user to save and quit (and run package) or allows them to cancel and it will simply repeat at the next policy check-in interval.

#!/bin/sh
#shorten path for JAMFHelper to abreviate following lines
JAMFHELPER="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

#determine if Acrobat is running:
IsAcrobatRunning=$(pgrep -l "Acrobat" | cut -c6-30)
if [ "$IsAcrobatRunning" = "AdobeAcrobat" ] ; then
echo "Detected running Acrobat instance, prompting user to quit and upgrade"

# Get the user's selection
RESULT=$JAMFHELPER -windowType hud -title Updates Required -heading Adobe Acrobat -description "There is a pending Adobe Acrobat security update.  Please quit out of Acrobat now, as the installation of this software will fail if it detects a Acrobat running during the installation. Click OK to indicate that Acrobat has been quit and to upgrade now, Cancel will re-try in one hour. Thank you for your patience while we upgrade." -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns -button1 "Cancel" -button2 "OK")
echo "jamf helper result was $RESULT";
if [ "$RESULT" == "0" ]; then
echo "Clicked OK, time to quit Acrobat!"
/usr/sbin/jamf policy -trigger InstallCachedAcrobat
 exit 0
else
         echo "user chose Cancel";   
     exit 1

fi
echo "Acrobat is not running, proceeding with upgrade"
/usr/sbin/jamf policy -trigger InstallCachedAcrobat
exit 0
5 REPLIES 5

brian_stewart
New Contributor
New Contributor

@Taylor.Armstrong What issues are you seeing?

m_donovan
Contributor III

I think your RESULT line is missing a leading $( for example RESULT=$($JAMFHELPER ....)

and

-trigger should be -event

brian_stewart
New Contributor
New Contributor

I took a minute to test out your script, and found a few things that needed to be tweaked:
- There are two "if" statements, but only one closing "fi" statement
- The "RESULT=$JAMFHELPER ..." line has a closing paren but no opening paren. To run a command and capture the result it needs to be in the format result="$(cmd args)", but this looks like result=$cmd args). This is easier to see if you break the jamfHelper statement up over multiple lines for readability.
- The result check if [ "$RESULT" == "0" ] should actually be if [ "$RESULT" == "2" ] if testing for the OK button click.

It is easier to code and debug this on a local machine if possible, and then copy/paste the script up to the JSS when it is working.

I have made the recommended changes to your script and attache it here. It appears to be working on my machine, so hopefully it gets you closer at least.

#!/bin/bash

export PATH="/usr/sbin:$PATH"

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

MESSAGE="There is a pending Adobe Acrobat security update.  
Please quit out of Acrobat now, as the installation of this 
software will fail if it detects a Acrobat running during 
the installation. Click OK to indicate that Acrobat has been 
quit and to upgrade now, Cancel will re-try in one hour. 
Thank you for your patience while we upgrade."

# Determine if Acrobat is running
IsAcrobatRunning=$(pgrep -l "Acrobat" | cut -c6-30)

if [ "$IsAcrobatRunning" = "AdobeAcrobat" ] ; then
  echo "Detected running Acrobat instance, prompting user to quit and upgrade"

  # Get the user's selection
  result=$("$JAMFHELPER" -windowType hud 
                         -title "Updates Required" 
                         -heading "Adobe Acrobat" 
                         -description "$MESSAGE" 
                         -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns" 
                         -button1 "Cancel" 
                         -button2 "OK")

  echo "User choice: $result"

  if [ "$result" == "2" ]; then
    echo "Clicked OK, time to quit Acrobat!"
    jamf policy -trigger InstallCachedAcrobat
    exit 0
  else
    echo "User chose Cancel"
    exit 1
  fi
else
  echo "Acrobat is not running, proceeding with upgrade"
  jamf policy -trigger InstallCachedAcrobat
  exit 0
fi

Taylor_Armstron
Valued Contributor

Thank you so much guys - think I'd just gotten pulled away from my desk too many times during the day, and my eyes were starting to cross staring at the code.

Only thing left to do now is to have the "OK" button also send a "kill" command to Acrobat if the user did not quit out, and think I've finally gotten past this one.

emily
Valued Contributor III
Valued Contributor III