I am trying to read status of do not disturb or dnd using applescript.
For some reason, it always return "1" no matter what if the dnd is on or off.
do shell script "defaults -currentHost read ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb"
Stack Editor: Script Editor to create and run the script OS: macOS Monterey
CodePudding user response:
If you don't mind reading it via the UI on Mac OS Monterey
log getDNDStatus()
on getDNDStatus()
set currentState to 1
tell application "System Events" to tell process "ControlCenter"
click of menu bar item "Control Center" of menu bar 1
if exists (first checkbox of front window whose title is "Focus") then set currentState to 0
end tell
tell application "System Events" to key code 53 -- Escape to close the control center popup
currentState
end getDNDStatus