From a84b44268aec10ed001caecdc01bfee8b91714e7 Mon Sep 17 00:00:00 2001 From: Vasilii Polikarpov <126792224+vpolikarpov-akvelon@users.noreply.github.com> Date: Fri, 27 Oct 2023 09:32:43 +0200 Subject: [PATCH] [Mac OS] Fix logic for retrying AppleScript execution (#8662) --- images/macos/provision/core/commonutils.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/images/macos/provision/core/commonutils.sh b/images/macos/provision/core/commonutils.sh index cbe0b9c4cf23..d93cb708cdd9 100644 --- a/images/macos/provision/core/commonutils.sh +++ b/images/macos/provision/core/commonutils.sh @@ -36,16 +36,20 @@ fi # System Preferences -> Security & Privacy -> General -> Unlock -> Allow -> Not now if is_Monterey; then if is_Veertu; then - echo "Executing AppleScript to change security preferences (with retries)" - retry=5 - while [ $retry -gt 0 ]; do + for retry in {4..0}; do + echo "Executing AppleScript to change security preferences. Retries left: $retry" { + set -e osascript -e 'tell application "System Events" to get application processes where visible is true' - } - osascript $HOME/utils/confirm-identified-developers.scpt $USER_PASSWORD + osascript $HOME/utils/confirm-identified-developers.scpt $USER_PASSWORD + } && break - retry=$((retry-1)) - echo "retries left "$retry + if [ "$retry" -eq 0 ]; then + echo "Executing AppleScript failed. No retries left" + exit 1 + fi + + echo "Executing AppleScript failed. Sleeping for 10 seconds and retrying" sleep 10 done else