I'm trying to read macOS notifications title and subtitle using AppleScript. I managed to get the title using the example posted here (number 5), but I also need to get the subtitle.
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:
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With