Jamf Prompt to quit application script

Captainamerica
Contributor II

I am looking for a quite "simple" script that prompt the user to close an application

Like with Adobe Remote updater it can update applications, when they are closed. So Would like a script that checks if appliation is open. If it is, it prompt the user to close it and afterwards the adobe remote updater can run

But can of course also work with other applications like Office etc

Do anyone has something they want to share? I found some but mostly are with cocoa, that I prefer not to use as it is getting legacy as I can read

1 REPLY 1

Captainamerica
Contributor II

Actually found this what I am searching for

#!/bin/bash


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

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

MESSAGE="There is a pending Microsoft Office security update.  
Click Close button to quit Office Application button below to. 

NOTE Save your work first


Click Cancel to re-try in one hour."

# Determine if Outlook is running
IsOutlookRunning=$(pgrep -l "Microsoft Outlook")

if [ "$IsOutlookRunning" ] ; then
  echo "Detected running Outlook instance, prompting user to quit and upgrade"

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

  echo "User choice: $result"

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

Is there a way to build in that it closes more application without I have to make a script for each office application. And also, Can I rezise the button size as it is to small to contain all text on button 2