From bd5dce3b8567cab3c6d18e7889ce321c58f91073 Mon Sep 17 00:00:00 2001 From: Armin Briegel <1933192+scriptingosx@users.noreply.github.com> Date: Thu, 12 Mar 2020 12:21:08 +0100 Subject: [PATCH] removed checkRunningProcesses --- checkrunningprocesses.sh | 62 ---------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 checkrunningprocesses.sh diff --git a/checkrunningprocesses.sh b/checkrunningprocesses.sh deleted file mode 100644 index 341e964..0000000 --- a/checkrunningprocesses.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/zsh - -export PATH=/usr/bin:/bin:/usr/sbin:/sbin - -blockingProcesses=( Notes firefox "Activity Monitor" "Microsoft Word" ) - - -# functions -consoleUser() { - scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }' -} - -runAsUser() { - cuser=$(consoleUser) - if [[ $cuser != "loginwindow" ]]; then - uid=$(id -u "$cuser") - launchctl asuser $uid sudo -u $cuser "$@" - fi -} - -displaydialog() { # $1: message - message=${1:-"Message"} - runAsUser /usr/bin/osascript -e "button returned of (display dialog \"$message\" buttons {\"Not Now\", \"Quit and Update\"} default button \"Quit and Update\")" -} - -# 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?") - if [[ $button = "Not Now" ]]; then - echo "user aborted update" - exit 1 - else - runAsUser osascript -e "tell app \"$x\" to quit" - fi - countedProcesses=$((countedProcesses + 1)) - countedErrors=$((countedErrors + 1)) - fi - done - - 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 "no more blocking processes, continue with update" - -exit 0 -