简体   繁体   English

如何使用 AppleScript 获取通知副标题/正文?

[英]How to get notification subtitle/body using AppleScript?

I'm trying to read macOS notifications title and subtitle using AppleScript.我正在尝试使用 AppleScript 读取 macOS 通知标题和副标题。 I managed to get the title using the example posted here (number 5), but I also need to get the subtitle.我设法使用 此处发布的示例(编号 5)获得标题,但我还需要获得副标题。

Here is the code that returns the title:这是返回标题的代码:

on run
    tell application "System Events"
        tell process "Notification Center"
            set theseWindows to every window
            set theseTitles to {}
            repeat with thisWindow in theseWindows
                try
                    set thisTitle to the value of static text 1 of thisWindow
                    set the end of theseTitles to thisTitle
                end try
            end repeat
            return theseTitles
        end tell
    end tell
end run

Does anyone know how I can get the notification subtitle?有谁知道我如何获得通知副标题?

Running the following example AppleScript code in Script Editor :脚本编辑器中运行以下示例AppleScript代码

display notification "Body Text Line" with title "Title Text Line" subtitle "Subtitle Text Line"

Produces this notification:生成此通知:

在此处输入图片说明

Then running the following example AppleScript code in Script Editor :然后在脚本编辑器中运行以下示例AppleScript代码

tell application "System Events"
    tell application process "NotificationCenter"
        get value of static text 1 of window 1
        get value of static text 1 of scroll area 1 of window 1
        get value of static text 2 of scroll area 1 of window 1
    end tell
end tell

Shows the following output in the Replies pane of Script Editor :脚本编辑器回复窗格中显示以下输出:

tell application "System Events"
    get value of static text 1 of window 1 of application process "NotificationCenter"
        --> "Title Text Line"
    get value of static text 1 of scroll area 1 of window 1 of application process "NotificationCenter"
        --> "Subtitle Text Line"
    get value of static text 2 of scroll area 1 of window 1 of application process "NotificationCenter"
        --> "Body Text Line"
end tell


As you can see, it's the get value of static text 1 of scroll area 1 of window 1 which returns the subtitle .如您所见,它get value of static text 1 of scroll area 1 of window 1get value of static text 1 of scroll area 1 of window 1它返回了子标题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM