【问题标题】:How to get notification subtitle/body using AppleScript?如何使用 AppleScript 获取通知字幕/正文?
【发布时间】:2020-04-01 22:26:43
【问题描述】:

我正在尝试使用 AppleScript 读取 macOS 通知标题和副标题。我设法使用发布的示例here(编号 5)获得标题,但我还需要获得副标题。

这是返回标题的代码:

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

有谁知道如何获取通知字幕?

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    脚本编辑器中运行以下示例 AppleScript 代码

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

    产生此通知:

    然后在脚本编辑器中运行以下示例 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
    

    Script EditorReplies 窗格中显示以下输出:

    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
    


    如您所见,返回字幕的是get value of static text 1 of scroll area 1 of window 1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-11
      • 2018-11-07
      相关资源
      最近更新 更多