Skip to content

Instantly share code, notes, and snippets.

@adam-zethraeus
Created April 28, 2021 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adam-zethraeus/3faca09d63569a09fdcd3feb53fc48c3 to your computer and use it in GitHub Desktop.
Save adam-zethraeus/3faca09d63569a09fdcd3feb53fc48c3 to your computer and use it in GitHub Desktop.
dndkill — disable macOS Big Sur Do-Not-Disturb (even if scheduled)
#!/bin/bash
rootPlist=$(plutil -extract dnd_prefs xml1 -o - /Users/"$USER"/Library/Preferences/com.apple.ncprefs.plist)
dataPlistB64=$(echo $rootPlist | xmllint --xpath "string(//data)" - )
dataPlist=$(echo $dataPlistB64 | base64 --decode | plutil -convert xml1 - -o -)
scheduleDict=$(echo $dataPlist | xmllint --xpath "//dict/key[text()='scheduledTime']/following-sibling::*[1]" -)
userPrefDict=$(echo $dataPlist | xmllint --xpath "//dict/key[text()='userPref']/following-sibling::*[1]" -)
end=$(echo $scheduleDict | xmllint --xpath "number(//dict/key[text()='end']/following-sibling::*[1])" -)
start=$(echo $scheduleDict | xmllint --xpath "number(//dict/key[text()='start']/following-sibling::*[1])" -)
scheduleEnabled=$(echo $scheduleDict | xmllint --xpath "name(//dict/key[text()='enabled']/following-sibling::*[1])" -)
userEnabled=$(echo $userPrefDict | xmllint --xpath "name(//dict/key[text()='enabled']/following-sibling::*[1])" -)
dataPlistWithoutUserPref=$( [[ $(echo $dataPlist | plutil -extract userPref xml1 - >/dev/null 2>&1) ]] \
&& echo $dataPlist | plutil -remove userPref - -o - \
|| echo $dataPlist )
dataPlistWithoutScheduleOrUserPref=$( [[ $(echo $dataPlistWithoutUserPref | plutil -extract userPref xml1 - >/dev/null 2>&1) ]] \
&& echo $dataPlistWithoutUserPref | plutil -remove userPref - -o - \
|| echo $dataPlistWithoutUserPref )
dataPlistWithSettings=$(\
echo $dataPlistWithoutScheduleOrUserPref | \
plutil -insert userPref -xml "
<dict>
<key>date</key>
<date>$(date -u +"%Y-%m-%dT%H:%M:%SZ")</date>
<key>enabled</key>
<false/>
<key>reason</key>
<integer>1</integer>
</dict> " - -o - | \
plutil -insert scheduledTime -xml "
<dict>
<key>enabled</key>
<false/>
<key>end</key>
<real>$end</real>
<key>start</key>
<real>$start</real>
</dict> " - -o -
)
payload=$(echo $dataPlistWithSettings | plutil -convert binary1 - -o - | xxd -p | tr -d '\n')
defaults write com.apple.ncprefs dnd_prefs -data "$payload"
pgrep usernoted | xargs kill -9
while [[ $(pgrep usernoted) == "" ]]; do sleep 0.1; done
# <?xml version="1.0" encoding="utf-8"?>
# <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
# "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
# <plist version="1.0">
# <dict>
# <key>dndDisplayLock</key>
# <false />
# <key>dndDisplaySleep</key>
# <true />
# <key>dndMirrored</key>
# <true />
# <key>facetimeCanBreakDND</key>
# <false />
# <key>repeatedFacetimeCallsBreaksDND</key>
# <false />
# </dict>
# </plist>
# <key>scheduledTime</key>
# <dict>
# <key>enabled</key>
# <true/>
# <key>end</key>
# <real>420</real>
# <key>start</key>
# <real>1320</real>
# </dict>
# <key>userPref</key>
# <dict>
# <key>date</key>
# <date>2021-04-28T06:18:24Z</date>
# <key>enabled</key>
# <true/>
# <key>reason</key>
# <integer>1</integer>
# </dict>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment