如何使用 AppleScript 获取通知 subtitle/body?
How to get notification subtitle/body using AppleScript?
我正在尝试使用 AppleScript 读取 macOS 通知标题和副标题。我设法使用发布的示例 here(第 5 个)获得了标题,但我还需要获得副标题。
这是 returns 标题的代码:
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
有谁知道我怎样才能得到通知副标题?
运行下面的例子AppleScript代码在脚本编辑器:
display notification "Body Text Line" with title "Title Text Line" subtitle "Subtitle Text Line"
生成此通知:
然后运行下面的例子 AppleScript code in 脚本编辑器:
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
在脚本编辑器的回复窗格中显示以下输出:
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
returns 副标题。
我正在尝试使用 AppleScript 读取 macOS 通知标题和副标题。我设法使用发布的示例 here(第 5 个)获得了标题,但我还需要获得副标题。
这是 returns 标题的代码:
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
有谁知道我怎样才能得到通知副标题?
运行下面的例子AppleScript代码在脚本编辑器:
display notification "Body Text Line" with title "Title Text Line" subtitle "Subtitle Text Line"
生成此通知:
然后运行下面的例子 AppleScript code in 脚本编辑器:
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
在脚本编辑器的回复窗格中显示以下输出:
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
returns 副标题。