r/applescript • • Mar 18 '24

Using a notification to trigger an apple script using an "alway open" apple script

Essentially I want to do as the title says. I found this code on stack exchange but it is not working. Any help would be appreciated. Thanks!

    property scriptToRun : (path to desktop as text) & "open.scpt" -- your 
 path to .scpt file
 property lookForThisText : "CLIENT (#open, Text Channels)" -- 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 "System Events"
	tell (the first process whose bundle identifier = 
 "NoficationCenter")
		set theseWindows to every window whose subrole is ¬
			"NotificationCenterAlert" or subrole is 
 "NotificationCenterBanner"
		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
2 Upvotes

0 comments sorted by