2022-02-10 18:10:43 +03:00
|
|
|
#!/bin/bash -e -o pipefail
|
2023-11-28 02:25:03 +01:00
|
|
|
################################################################################
|
|
|
|
|
## File: configure-windows.sh
|
|
|
|
|
## Desc: Close open windows
|
|
|
|
|
################################################################################
|
2022-02-10 18:10:43 +03:00
|
|
|
|
2023-10-12 11:31:35 +02:00
|
|
|
source ~/utils/utils.sh
|
|
|
|
|
|
|
|
|
|
# Close System Preferences window because in Ventura arm64 it is opened by default on Apperance tab
|
2023-11-10 18:53:24 +01:00
|
|
|
if is_Arm64; then
|
2023-10-12 11:31:35 +02:00
|
|
|
echo "Close System Preferences window"
|
|
|
|
|
osascript -e 'tell application "System Preferences" to quit'
|
|
|
|
|
fi
|
|
|
|
|
|
2022-02-17 11:40:06 +03:00
|
|
|
retry=10
|
2023-12-21 14:48:28 +01:00
|
|
|
while [[ $retry -gt 0 ]]; do
|
2022-02-17 11:40:06 +03:00
|
|
|
openwindows=$(osascript -e 'tell application "System Events" to get every window of (every process whose class of windows contains window)') && break
|
|
|
|
|
retry=$((retry-1))
|
2023-12-21 14:48:28 +01:00
|
|
|
if [[ $retry -eq 0 ]]; then
|
2022-02-17 11:40:06 +03:00
|
|
|
echo "No retry attempts left"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
sleep 30
|
|
|
|
|
done
|
2024-04-23 11:06:38 +02:00
|
|
|
IFS=',' read -r -a windowslist <<< "$openwindows"
|
2022-02-10 18:10:43 +03:00
|
|
|
|
2024-01-09 14:47:31 +01:00
|
|
|
if [[ -n ${openwindows} ]]; then
|
2022-02-10 18:10:43 +03:00
|
|
|
echo "Found opened window:"
|
|
|
|
|
fi
|
|
|
|
|
|
2024-04-23 11:06:38 +02:00
|
|
|
for key in ${!windowslist[@]}; do
|
|
|
|
|
if [[ ${windowslist[$key]} =~ "NotificationCenter" ]]; then
|
|
|
|
|
echo "[Warning] ${windowslist[$key]}"
|
2022-02-10 18:10:43 +03:00
|
|
|
else
|
2024-04-23 11:06:38 +02:00
|
|
|
echo " - ${windowslist[$key]}" | xargs
|
2022-02-10 18:10:43 +03:00
|
|
|
scripterror=true
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2024-01-09 14:47:31 +01:00
|
|
|
if [[ ${scripterror} = true ]]; then
|
2022-02-10 18:10:43 +03:00
|
|
|
exit 1
|
|
|
|
|
fi
|