Getting Safari Page Content Into a KM Variable

Hello,

I'm trying to save the content of a Safari page into a variable, so I can quickly search it for a specific term and do something based on the results. I've been trying to clunk my way through it with AppleScript, but am getting errors (because I have only the faintest sliver of a hint of what I'm doing).

I've been trying to adapt this method to suit my needs, in this way:

set the webpage_content to ""
tell application "Safari" to set the webpage_content to the text
tell application "Keyboard Maestro Engine"
   set the value of variable "pageContent" to the text
end tell

And am getting this error:

error "Keyboard Maestro Engine got an error: Can’t make text into type text." number -1700 from text to text

What simple thing am I misunderstanding?

Thank you

(I wish I'd payed better attention in college, and had continued after graduation. I really ought to buckle down, buy a book, and start learning this stuff properly.)

Hey Christian,

The devil is in the details…

Note how this is different from yours:

tell application "Safari" to set the webpage_content to the text of front document

tell application "Keyboard Maestro Engine"
   setvariable "pageContent" to webpage_content
end tell

-Chris

1 Like

I see now. Thank you for your help; this does exactly what I want and significantly improves my workflow. I’ve bookmarked some resources you’ve linked to in the past, and it’s about time I actually got down to it. Off to Amazon…

Thank you!