r/applescript • • Aug 03 '21

Copy text of system notifications

Hi guys,

I'm really new to scripting and programming but I'm attempting to learn.

To tell you shortly about my project: I've recently installed Alfred on my computer and discovered the magic of Workflows. In Alfred i can run applescript that then connects to Alfreds own tools. I want to create a Workflow where i can copy an unknown incoming calls phone number and then make Alfred do a custom lookup on different websites that checks phones numbers here in the nordics (like Eniro.se / Hitta.se )

The question is: Is there anyone out there that might be able to help me understand more about getting the text out of a notification and then also setting the data to a specified variable that i can forward to Alfred?

I've searched around the web to get answers but there are only a few mentions on how to copy text from a notification and none of them seems to work.

I've tried the following scripts:

tell application "System Events"
       set Nummer to get value of static text of scroll area 1 of window 1 of process "NotificationCenter"
end tell

& also tried:

return value of static text of scroll area 1 of window 1 of process "NotificationCenter"

& also this:

tell application "System Events" to ¬    
get value of ¬         
static text of ¬         
scroll area 1 of ¬         
window 1 of ¬        
process "NotificationCenter"

I'm trying to find a guide that explains more about the Notification Center and how i can extract the text. Example: Why should i use: Scroll area 1?

The only thing i can find regarding Notification center is about how to display text, not how to copy or handle data in it etc. like this: https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/DisplayNotifications.html

All the best / P

3 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/Ratkay Aug 04 '21

The script that i've tried does not store the data in a variable.

I've tried to use

display dialog ""& Nummer --Nummer is the variable ofc 

or

set the clipboard to Nummer

to confirm that it actually picked up something from the notification :)

after i actually can successfully copy the number of an incoming call i want to pass the variable along in Alfreds Workflow by just assining the data of the variable to something called {query} :)

So when an unkown number calls me i can just use a "hotkey" like cmd+space to do this automation for me and look up the number on several different websites :)