Open URL Links for Highlighted Text on a Safari Webpage

I want to open the URL links for the highlighted text in a Safari webpage all at once in new Safari tabs.

Here's an example:

I have searched the internet and the Keyboard Maestro Forum for "URL Extractor" / Want to Create a Macro Which Would Open All the Links in a Document, but haven't found a solution for my problem yet (I have no programming knowledge).

Can someone help me?

Hello, @gglick, a genius, wrote a macro here : How to Trigger an App Independent Services Menu Item

Thanks for the answer @ronald. I also saw the entry then, and thought to myself: Funny, that reminds me of my old question.

The problem with the Safari links is that they are only highlighted, but not in full form.

The previous macros only work if they are fully written out. That's exactly my problem.

When I answered the last entry, I stumbled across another old post that I saw weeks ago that goes in the right direction.

But I didn't quite understand this. Above all, I can't download the solution. Maybe @ccstone can help me.

1 Like

There is no download button for scripts. Just copy the script and paste into Script Editor, or even better into Script Debugger 7.

I apologize for misleading you. I am probably the least qualified member of the forum.
For starters, did you know that you can highlight in Safari the text in your post → context menu → services → add to Safari reading list. It works. I tried it.

I also know the following entry: :wink:

But I didn't want to go exactly this way, because it seems to me too cumbersome.

I just wanted to know if there was an easy and direct way to open the links in marked text in new Safari tabs.

@JMichaelTX

The problem's been on my mind for some time. And I can remember again: I tried the script with the Script Editor, and also tried Execute AppleScript in Keyboard Maestro. But since it's a prototype and I don't understand it, of course nothing came out...

I have also read many times here in the forum that the
Light version of Script Debugger 7 is free, but since my only programming skill is Basic from the late 80's, it doesn't really help me either.

The problem occurs so often that I have now dared to create a new entry.

Hey @Tomaso71,

I'll do this part for you – extract the href links from the highlighted/selected text in Safari.

It places each URL 1 per line in a variable, and from there you can open each one in a tab in Safari with the Lines In collection.

Personally I'd do the whole job in AppleScript (other than the copy action), because it's much more efficient when consolidated – however I've broken it up in such a way that (I think) most folks will find the process a bit more friendly.

If you have trouble finishing your task just let me know, and I'll help out.

-Chris


Safari -- Extract Links from Selection on Front Web Page.kmmacros (11 KB)

2 Likes

@ccstone

I wanted to create a new window for the first link and a new tab for all other links.

It works, but it's probably awkward. Can you look over it again and tell me how to do it better? Especially with "variable housekeeping" something might be missing.

Many thanks for your help...

@test - extract all links in selected text on front web page (ccstone).kmmacros (13.0 KB)

@Tomaso71

I didn't know how to get HTML links from selected text like this the way @ccstone did, but I think I can at least help out with streamlining his excellent macro. This version uses local variables, so there's no need for any housekeeping, and keeps everything inside one For Each loop. I also got rid of the clipboard seed based actions since KM's native Copy action has a pause built in:

@test - extract all links in selected text on front web page (ccstone) 1.1.kmmacros (9.8 KB)

1 Like

@gglick
Thank you so much for the solution. That's exactly what I had in mind.

@ccstone
I hadn't thought of this solution originally. But displaying the text in a window also has an advantage: Since I also use the App Popclip, I can first display all links and then simply open the desired link via the "Open Link" icon! Thanks again here.

While testing, I found out that the App Popclip implements exactly the solution of @gglick, only not in a new window, but in new tabs in the old window!!! I didn't know that...

1 Like

Hey Folks,

Here's the mostly AppleScript version.

-Chris


Safari -- Extract Links from Selection on Front Web Page and Open Them v2.00.kmmacros (10 KB)

1 Like