property scriptToRun : (path to desktop as text) & "your.scpt" -- your path to .scpt file
property lookForThisText : "Search For This Text In Notification Windows" -- your search term
property theseTitles : {}
on idle
getNotificationTitles()
delay 0.1
if theseTitles contains lookForThisText then
---------------------------------------------------------------
delay 6 -- Gives Banner Time To Self Close
--tell current application to beep 5 -- Just For Testing
run script alias scriptToRun
---------------------------------------------------------------
end if
return 1 -- in seconds
end idle
on quit
-- Executed when the script quits
continue quit -- allows the script to quit
end quit
on getNotificationTitles()
-- This Gets The Titles Of The Currently Displaying Notification Alerts And Banners
tell application id "com.apple.SystemEvents"
tell (the first process whose bundle identifier = "com.apple.notificationcenterui")
set theseWindows to every window whose subrole is ¬
"AXNotificationCenterAlert" or subrole is "AXNotificationCenterBanner"
set theseTitles to {}
repeat with thisWindow in theseWindows
set titleText to the value of static text 1 of thisWindow
set the end of theseTitles to titleText
set subTitleText to the value of static text 1 of scroll area 1 of thisWindow
set the end of theseTitles to subTitleText
set notificationText to the value of static text 2 of scroll area 1 of thisWindow
set the end of theseTitles to notificationText
end repeat
end tell
end tell
end getNotificationTitles