How do I add a "Please close the following applications" to a .pkg installer

ryanscherding
New Contributor II

I am looking to use composer to spin off a printer installer (.pkg) for our independent contractors, who have BYOD computers, and therefore are not enrolled in our JSS.

I have everything good to go with a lpadmin command added to the postinstall script from the driver installer, and the command to use the system print dialogue instead of chrome's. However if chrome is open during the installation it will still use the chrome print window, so I need to have chrome closed before the installation runs.

I don't want to just kill chrome, as users may have tabs open so I figure a popup window would be the best solution, that halts the install until chrome is no longer running. Though I am unfamiliar with how to do this, so any guidance would be greatly appreciated.

3 REPLIES 3

rhooper
Contributor III

Can you go into the policy that adds the printers, Self Service that states users must read Description?

But if you are not using SS portal, you may be able to add a second script like a popup window or JAMF Helper Box to run before the other script /policy runs.

alexjdale
Valued Contributor III

I believe you'd want to add a preflight script, which would do its thing before the payload is installed. It could pgrep for the Chrome process, prompt the user to quit it, and loop until Chrome is no longer running. Then the preflight script would exit and the installation would proceed.

merps
Contributor III

Here's the pgrep logic that we use, borrowed heavily from a script posted a while back by @kitzy.

This won't work directly since you're working with unmanaged systems, but the logic is there.
$processNames is passed into the script with this example, but you could just as easily just define Chrome at the top.

This snippet uses jamfhelper for prompting, so you'll probably want to do something with Applescript for the promptUser line instead on systems without jamf.

for process in $processNames
do

PID="" # Clear PID to elimnate false positives

PID=`pgrep "$process"` # Get application PID

if [ ! -z "$PID" ] # Detect if application is running
    then
        # Prompt user to quit the running application
        echo "$process is running, prompting user to quit"
        promptUser "$heading1" "$description1" "$process"
        if [[ $promptResult = 0 ]] # 0 indicates user clicked button 1
            then
                echo "User clicked OK"
                # Ask application to quit
                osascript -e "tell application "$process" to quit"
        elif [[ $promptResult = 2 ]] # 2 indicates user clicked button 2
            then
                # Echo for the log, then exit
                echo "User clicked Cancel"
                exit 0
        elif [[ $promptResult = 1 ]] # 1 indicates jamfHelper was unable to launch
            then
                echo "ERROR: jamfHelper returned status 1: unable to launch"
                exit 1
            else
                # If jamfHelper returns anything other than 0, 1 or 2,
                # report an error to the JSS and exit
                echo "ERROR: an unknown error occurred"
                exit 2
        fi
    else
        echo "$process not running, moving on"
fi