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}"