在屏幕锁定时读取 MacOs 通知 AppleScript

问题描述 投票:0回答:1

我已经成功地组合了一个AppleScript,它可以读取通知并输出这些文本。虽然它在显示屏打开并解锁时可以工作,但我无法在锁定屏幕上能够阅读通知。

#!/usr/bin/osascript
on run
    delay 6.0 -- wait for locking the screen
    tell application "System Events"
        try
            set _groups to groups of UI element 1 of scroll area 1 of group 1 of window "Notification Center" of application process "NotificationCenter"
            repeat with _group in _groups
                return the value of static text 1 of _group --limit to one notification for the moment
            end repeat
        end try
    end tell
end run

这是我当前的代码,它成功读取了macOS Ventura上最新通知的通知标题。但是,锁定屏幕 (⌘ + Ctrl + Q) 并尝试读取通知后,代码不会输出任何内容,即使通知在同一位置仍然可见

最终目标:

每 10 秒执行一次此脚本(具有所需的错误处理),即使显示器已锁定,并让它读取通知以将其传递给不同的脚本。


如果有任何其他方式通过脚本读取 macOS 通知,也欢迎。

macos automation notifications applescript
1个回答
0
投票

这是一个Python脚本,您可以使用它来获取通知内容:

https://github.com/ydkhatri/MacForensics/blob/master/macNotifications.py
© www.soinside.com 2019 - 2024. All rights reserved.