Set variable to result of JavaScript in Safari

Hi!

I’m building a macro to launch my workspace for daily Swift learning. I want Keyboard Maestro, to automatically create a playground for me so, I need the title of today’s topic. It’s contained by the H2 tag, with class "text-center". The website has two matching elements, and I need the first one. I want to run JavaScript in Safari to set a Keyboard Maestro variable to contents (text) of this element, so I can use it later to name the file. What's the JavaScript code for that?

This is the Website

Thank you in advance and have a great day!

Hey @anon71407114,

Try this now:

document.querySelector('#tutorials h2').innerText

-Chris

1 Like

Thank you so much, it is exactly what I needed.

1 Like