Posted on 09-14-2022 08:32 AM
This is my script to notify user that app will be closed.
It is working without trying to use parameters while configuring script.
With coded data to processName and appName notification is working flawlessly.
But I don't want to create script for each app that needs this functionality, that's why I'm asking for help with this script.
#!/bin/bash
#set -x
processName=$4
appName=$5
message="$appName app is currently open.
By pressing <Proceed>
app will be closed and process will continue."
echo "$(date) | Waiting for other [$processName] processes to end"
while ps aux | grep "$processName" | grep -v grep &>/dev/null; do
HELPER=`/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -defaultButton 1 -lockHUD -description "$message" -windowPosition c -title "$5 Update/Installation" -windowType hud -button1 "Proceed" -alignDescription center -alignHeading center`
if [ "$HELPER" == "0" ]; then
echo "$(date) | User clicked UPGRADE button"
terminate="true"
fi
if [[ $terminate == "true" ]]; then
echo "$(date) | + [$appName] running, terminating [$processName]..."
pkill -f "$processName"
fi
delay=7
echo "$(date) | + Another instance of $processName is running, waiting [$delay] seconds"
sleep $delay
done
echo "$(date) | No instances of [$processName] found, safe to proceed"
Posted on 09-14-2022 08:52 AM
Are you seeing an issue with it when using the script parameters? If so, you didn't describe the problem.
I would consider putting double quotes around the parameters when assigning to the variable names, like this:
processName="$4"
appName="$5"
I can't be sure if any issue you're seeing with it is related to that, but always a good idea to double quote items like that since 'appName' in particular could easily have spaces in the string.
Posted on 09-15-2022 02:28 AM
The close application function works as it should, but even with the quotes there is a loop, the application is closed and a popup is saying that app is open and needs to be closed.
Without parameters it is closing application and going with application install.
Posted on 09-19-2022 08:43 AM
Installomator has this function built in, you can take a look at their script to pull what you need.