Skip to content

Instantly share code, notes, and snippets.

@stevenirby
Created August 25, 2019 09:05
Show Gist options
  • Save stevenirby/0dc9ae8ed871ea1d792916254b5ea9c5 to your computer and use it in GitHub Desktop.
Save stevenirby/0dc9ae8ed871ea1d792916254b5ea9c5 to your computer and use it in GitHub Desktop.
Mute MacOS when do not disturb is on and you're not using the computer.
#!/bin/bash
#
# Fist check if do not disturb is on.
# Then check if screen is off, meaning you're not using the computer at that time.
# If do not disturb is on and you're not using the machine, mute the volume.
if [[ $(/usr/bin/defaults -currentHost read ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb) -eq 1
&& `echo $(/usr/sbin/ioreg -n IODisplayWrangler | grep -i IOPowerManagement | perl -pe 's/^.*DevicePowerState\"=([0-9]+).*$/\1/')/4 | bc` -eq 0 ]];
then
osascript -e "set Volume 0"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment