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
set DNDStatus to (do shell script "defaults -currentHost read com.apple.notificationcenterui doNotDisturb") as integer as boolean
下面是AppleScript Objective-C解决方案:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set defaults to current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.apple.notificationcenterui"
set DNDStatus to (defaults's valueForKey:"doNotDisturb") as boolean
4条答案
按热度按时间whhtz7ly1#
Monterey 解决方案
如果启用了“请勿打扰”,则返回
1
,否则返回0
。m2xkgtsf2#
如果你不介意通过Mac OS Monterey上的UI阅读它
7gcisfzg3#
在我的Catalina上,你的普通苹果脚本运行良好:
下面是AppleScript Objective-C解决方案:
kgqe7b3p4#
您也可以使用shell脚本: