如何阅读不要使用AppleScript打扰?

发布于 2025-01-20 03:58:31 字数 267 浏览 0 评论 0原文

我正在尝试使用AppleScript阅读不要打扰或DND的状态。

由于某种原因,无论DND是否打开或关闭,它总是返回“ 1”。

do shell script "defaults -currentHost read ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb"

堆 编辑器:脚本编辑器要创建并运行脚本 操作系统:Macos Monterey

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

写下不归期 2025-01-27 03:58:31

蒙特利的解决方案

#!/bin/bash
defaults read com.apple.controlcenter "NSStatusItem Visible FocusModes"

如果启用“请勿打扰”,则返回 1,否则返回 0

Solution for Monterey

#!/bin/bash
defaults read com.apple.controlcenter "NSStatusItem Visible FocusModes"

It returns 1 if "Do Not Disturb" is enabled, 0 otherwise.

王权女流氓 2025-01-27 03:58:31

如果您不介意通过 Mac OS Monterey 上的 UI 阅读它

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

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
趁微风不噪 2025-01-27 03:58:31

在我的 Catalina 上,你的普通 Apple 脚本工作正常:

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

On my Catalina your plain Apple-script works fine:

set DNDStatus to (do shell script "defaults -currentHost read com.apple.notificationcenterui  doNotDisturb") as integer as boolean

Here is AppleScript Objective-C solution:

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
水中月 2025-01-27 03:58:31

您也可以使用shell脚本:

#!/bin/bash
DNDStatus=$(defaults -currentHost read com.apple.notificationcenterui  doNotDisturb)
echo $DNDStatus

You can use a shell script too:

#!/bin/bash
DNDStatus=$(defaults -currentHost read com.apple.notificationcenterui  doNotDisturb)
echo $DNDStatus
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文