From 9e2fa6567076931c46c05bf06842a5c0d2899c79 Mon Sep 17 00:00:00 2001 From: Raptor399 Date: Tue, 12 Oct 2021 12:14:29 +0200 Subject: [PATCH 1/4] Added option to not interrupt Do Not Disturb full screen apps like KeyNote or Zoom --- CHANGELOG.md | 1 + fragments/functions.sh | 26 ++++++++++++++++++++++++++ fragments/header.sh | 10 ++++++++++ fragments/main.sh | 7 +++++++ 4 files changed, 44 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74d7b8f..f50b40c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Added bunch of new labels, and improved others. - Renamed `buildCaseStatement.sh` to `buildLabel.sh` and improved it a lot. It is a great start when figuring out how to create a new label for an app, or a piece of software. Look at the tutorials in our wiki. - Mosyle changed their app name from Business to Self-Service +- Added option to not interrupt Do Not Disturb full screen apps like KeyNote or Zoom with `INTERRUPT_DND="no"`. ## v0.6 - 2021-07-14 diff --git a/fragments/functions.sh b/fragments/functions.sh index ebf6e58..7725e80 100644 --- a/fragments/functions.sh +++ b/fragments/functions.sh @@ -616,4 +616,30 @@ finishing() { fi } +# Detect if there is an app actively making a display sleep assertion, e.g. +# KeyNote, PowerPoint, Zoom, or Webex. +# See: https://developer.apple.com/documentation/iokit/iopmlib_h/iopmassertiontypes +hasDisplaySleepAssertion() { + # Get the names of all apps with active display sleep assertions + local apps="$(/usr/bin/pmset -g assertions | /usr/bin/awk '/NoDisplaySleepAssertion | PreventUserIdleDisplaySleep/ && match($0,/\(.+\)/) && ! /coreaudiod/ {gsub(/^.*\(/,"",$0); gsub(/\).*$/,"",$0); print};')" + + if [[ ! "${apps}" ]]; then + # No display sleep assertions detected + return 1 + fi + + # Create an array of apps that need to be ignored + local ignore_array=("${(@s/,/)IGNORE_DND_APPS}") + + for app in ${(f)apps}; do + if (( ! ${ignore_array[(Ie)${app}]} )); then + # Relevant app with display sleep assertion detected + printlog "Display sleep assertion detected by ${app}." + return 0 + fi + done + + # No relevant display sleep assertion detected + return 1 +} diff --git a/fragments/header.sh b/fragments/header.sh index a845b98..0ede4db 100644 --- a/fragments/header.sh +++ b/fragments/header.sh @@ -102,6 +102,16 @@ REOPEN="yes" # - no App not reopened +# Interrupt Do Not Disturb (DND) full screen apps +INTERRUPT_DND="yes" +# options: +# - yes Script will run without checking for DND full screen apps. +# - no Script will exit when an active DND full screen app is detected. + +# Comma separated list of app names to ignore when evaluating DND +IGNORE_DND_APPS="firefox,Google Chrome,Safari,Microsoft Edge,Opera,Amphetamine,caffeinate" + + # NOTE: How labels work # Each workflow label needs to be listed in the case statement below. diff --git a/fragments/main.sh b/fragments/main.sh index dfba2c9..2127145 100644 --- a/fragments/main.sh +++ b/fragments/main.sh @@ -8,6 +8,13 @@ esac # MARK: application download and installation starts here +if [[ ${INTERRUPT_DND} = "no" ]]; then + # Check if a fullscreen app is active + if hasDisplaySleepAssertion; then + cleanupAndExit 1 "active display sleep assertion detected, aborting" + fi +fi + printlog "BLOCKING_PROCESS_ACTION=${BLOCKING_PROCESS_ACTION}" printlog "NOTIFY=${NOTIFY}" From cfdb884818134d7003f32dfdc8005d78b37b5d63 Mon Sep 17 00:00:00 2001 From: Raptor399 Date: Mon, 18 Oct 2021 16:12:44 +0200 Subject: [PATCH 2/4] Setting no default IGNORE_DND_APPS with example in comments. As per the discussion in the pull request. --- fragments/header.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fragments/header.sh b/fragments/header.sh index 0ede4db..43ebb7a 100644 --- a/fragments/header.sh +++ b/fragments/header.sh @@ -109,7 +109,9 @@ INTERRUPT_DND="yes" # - no Script will exit when an active DND full screen app is detected. # Comma separated list of app names to ignore when evaluating DND -IGNORE_DND_APPS="firefox,Google Chrome,Safari,Microsoft Edge,Opera,Amphetamine,caffeinate" +IGNORE_DND_APPS="" +# example that will ignore browsers when evaluating DND: +# IGNORE_DND_APPS="firefox,Google Chrome,Safari,Microsoft Edge,Opera,Amphetamine,caffeinate" # NOTE: How labels work From cf42f1f8b7d5263deabcc0e4810b83ae2867967b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Theilgaard?= Date: Thu, 25 Nov 2021 12:50:36 +0100 Subject: [PATCH 3/4] Moved change to top of the list --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f50b40c..8db070c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +- Added option to not interrupt Do Not Disturb full screen apps like Keynote or Zoom with `INTERRUPT_DND="no"`. + ## v0.7 - pre-release - default for `BLOCKING_PROCESS_ACTION`is now `BLOCKING_PROCESS_ACTION=tell_user` and not `prompt_user`. It will demand the user to quit the app to get it updated, and not present any option to skip it. In considering various use cases in different MDM solutions this is the best option going forward. Users usually choose to update, and is most often not bothered much with this information. If it's absoultely a bad time, then they can move the dialog box to the side, and click it when ready. @@ -7,7 +9,6 @@ - Added bunch of new labels, and improved others. - Renamed `buildCaseStatement.sh` to `buildLabel.sh` and improved it a lot. It is a great start when figuring out how to create a new label for an app, or a piece of software. Look at the tutorials in our wiki. - Mosyle changed their app name from Business to Self-Service -- Added option to not interrupt Do Not Disturb full screen apps like KeyNote or Zoom with `INTERRUPT_DND="no"`. ## v0.6 - 2021-07-14 From c98fd8f26cd62a3c1f59aa0ecd34f501e5258295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Theilgaard?= Date: Mon, 17 Jan 2022 09:46:41 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a9e96e..b815d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## v9? - We have moved the root check to the beginning of the script, and improved DEBUG handling with two different modes. `DEBUG=0` is still for production, and `1` is still for the DEBUG we previously knew downloading to the directory it is running from, but `2` will download to temporary folder, will detect updates, but will not install anything, but it will notify the user (almost as running the script without root before). -- Added option to not interrupt Do Not Disturb full screen apps like Keynote or Zoom with `INTERRUPT_DND="no"`. +- Added option to not interrupt Do Not Disturb full screen apps like Keynote or Zoom with `INTERRUPT_DND="no"`. Default is `"yes"` which is how it has worked until now. ## v8.0