From efefd1e9c9b9b48c420ec07ec009e65be656b44e Mon Sep 17 00:00:00 2001 From: Armin Briegel <1933192+scriptingosx@users.noreply.github.com> Date: Wed, 11 Mar 2020 11:12:46 +0100 Subject: [PATCH] now working as expected --- checkrunningprocesses.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/checkrunningprocesses.sh b/checkrunningprocesses.sh index 963fca6..183c6f6 100644 --- a/checkrunningprocesses.sh +++ b/checkrunningprocesses.sh @@ -23,16 +23,14 @@ displaydialog() { # $1: message runAsUser /usr/bin/osascript -e "button returned of (display dialog \"$message\" buttons {\"Not Now\", \"Quit and Update\"} default button \"Quit and Update\")" } - -countedProcesses=1 -countedErrors=0 -while [[ $countedProcesses -ne 0 ]]; do +# try at most 3 times +for i in {1..3}; do countedProcesses=0 for x in ${blockingProcesses}; do if pgrep -xq "$x"; then echo "process $x is running" # pkill $x - button=$(displaydialog "The Application $x needs to be updated. Quit the app to continue updating?") + button=$(displaydialog "The application $x needs to be updated. Quit the app to continue updating?") if [[ $button = "Not Now" ]]; then echo "user aborted update" exit 1 @@ -40,10 +38,25 @@ while [[ $countedProcesses -ne 0 ]]; do runAsUser osascript -e "tell app \"$x\" to quit" fi countedProcesses=$((countedProcesses + 1)) + countedErrors=$((countedErrors + 1)) fi done - if [[ $countedProcesses -ne 0 ]]; then - # give the user some time to quit the app - sleep 10 + + if [[ $countedProcesses -eq 0 ]]; then + # no blocking processes, exit the loop early + break + else + # give the user a bit of time to quit apps + sleep 30 fi done + +if [[ $countedProcesses -ne 0 ]]; then + echo "could not quit all processes, aborting..." + exit 1 +fi + +echo "everything is quit, continue with update" + +exit 0 +