Set Clipboard to RTF Hyperlink & Plain Text MD Link

I just discovered a cool, unexpected, benefit of this macro/script.
If you select a hyperlink from a Google Search, it will create a very clean hyperlink with ONLY the intended destination. IOW, it cuts out all that Google noise. :sunglasses:

3 Likes

I think I've found a better RegEx pattern for this. I'm going to test for awhile and if all goes well, I'll update the script here.

See my post here.

If you want to try the new RegEx pattern, you can replace this line in the function extractURLfromHyperlink(pstrHTML) in the AppleScript file:

set strRegEx to "<a.+?\\s*href\\s*=\\s*[\"\\']?([^\"\\'\\s>]+)[\"\\']?"

It is working very well for me so far.

###Note that I have made a major revision to my original post above to provide the complete, finished, Ver 1.0 release.

I have just uploaded Ver 1.1.

1 Like

Updated original post/download just now with a major revision.

Hi and good day,
Today I’m exploring this neat script.

And it works, the clipboard provides the earlier selected text as a hyperlink of the relevant page.

1.)
HOWever I get an error message:

*** SCRIPT ERROR ***
Action Result: OK
Script Msg: «class bhit»:OK, «class gavu»:false
Macro Aborted.

POSSIBLE CAUSE:
Invalid path or name of Script file.


As far as I can see the path is correct and the name of the script, too.

2.)
Also the context menu, for choosing MD, Plain Text, etc. only appeared the first time/ run, not later.

(I rebooted KM & KM engine)

What could be the reason?

/
with best regards,
Omar KN
Stockholm, Sweden

Hey Omar,

You installed everything where JM specifies?

You DO have the Satimage.osax installed?

-Chris

All 4 items are installed, also Satimage.

All 4 files are in ~/Documents/My KM Data

… or should the .kmmacros files be in a special folder somewhere else?

Here is a screendump: https://d.pr/free/i/Dwf6Xu

So the macro does work, except for the error message, and I rebooted, too.

And also Satimage: https://d.pr/free/i/nuRGyI

/
Any assistance would be fine!

With best regards,
Omar KN

I have not idea why you are getting that error msg -- something has changed with later macOS versions. When I wrote this script I was using Yosemite.

IAC, for now you can either ignore the error msg, or change the Macro Confirmation options from "Full" to "Brief". I'll post an update later to fix.

Added ( return “” --> NEW CODE 2018-03-09 ) to line 306 as acc. to Chris S.

/
okn

1 Like

This is great. Is it possible to set the font and point size as well?

Yes, but you have to change the script:

image

Near the top of the script you should find this line:

property fontStyleStr : "color:blue; font-family:verdana,geneva,sans-serif; font-size:14px;"

This is standard web page CSS styling, so change as you like.

This is an excellent script! Is it possible to copy the Title and URL automatically so it doesn't have a pop up? Then I can just paste into my desired destination.

Hi @James_Hawkins,

This action is there for a reason. It allows you to check the link before pasting it somewhere else. It also allows you to change the format at the last moment.

That said, if you don't need it, you can simply disable this action. But, make sure you set %Variable%DND_SCB__MarkDownType% to your desired format.

1 Like

How do I set %Variable%DND_SCB_MarkDownType% as my desired format exactly? Where do I change this?

Also, is it possible to have this only copy from Microsoft Edge web browser?

Thank you.

You may leave the action I said above enabled and run the macro once. It will remember your choice.

The macro will set the format to MD if you have not set.

It does not really matter as long as you run it only when Edge is the front browser. However, to make the macro run only when Edge is the front browser, put the macro in a macro group and set it to add Microsoft Edge to the list.
image

2 Likes

I seem to have gotten it to work, but why does it create a large two line gap when I paste? I pasted it at the white cursor location and it pastes two lines down.

Screen Shot 2021-10-01 at 5.07.34 PM

I have not used it before and just tried it. It did not add the two blank lines on my side.
I don't know what happened to yours. Did you change anything? If you did, the simplest way might be delete it and reinstall the macro.

1 Like