Best way to check what website I am currently in to make button actions and help with scaling

What I am trying to do is that I want to make a single macro that will take care of all the buttons that I might find on the internet and it will press on them with one single hotkey (cmd + m) in my case. So for example I can have something like this :

But I want perform a conditional check for what website I am currently at and then essentially make most common buttons I see on these websites and add them under the conditional if statement. I know I can get the url of currently active window with 'tell application "Safari" to return URL of front document' applescript. But then I need to do some pattern matching and check for a string and if it contains something like https://github then look for these buttons, if not go to next conditional statement and so on.

This brings a few questions. First with more websites and this macro growing bigger and bigger with every button, this seems to be an idea that can't really grow. Or can it? And I am curious whether what I am doing is a good way to go about it.

Thank you for any help.

Use a Switch or Case action, with a Text condition and the SafariURL token. This will handle any number of web sites.

1 Like

Hey Peter,

I believe I understood you correctly but my macro doesn't work.

I have this macro (courtesy of @JMichaelTX neat macro to post macros to topics quickly :))

safari: press buttons

safari- press buttons.kmmacros (30 KB)

And it doesn't work. What am I doing wrong. Also is this what you meant with switch statements?

Never mind, the github ones do work. Perhaps product hunt's one is not a button although it does look like one :

Am I doing my macro right? In theory as I expand it, it will have a lot of websites in this one action with different websites and their respective buttons.

Web page buttons are often not real buttons at all, so the Press Button action probably wont work.

However the Submit Safari Form or Click Safari Link actions might work.