Tinderbox Forum

How to copy this link from text window to the clipboard?

In the text window there is a link to the site written in one word. When you hover your cursor over the word, the link becomes visible. When you click on that word, the link goes to the site. I couldn’t find it: how to copy this link from this word to the clipboard?

Where? Could you show in a screen grab?

Option-click to select text inside a text link. OR, click outside the link, and drag through the link to select the link and the surrounding text.

Here is an example of a copied bottom line from this page:

when hovering the cursor over the salt with the link(screen1):

When you right-click on the salt with a link(screen2):
How do I heal the link shown on the screen1?

As Browse Links is greyed out, these are ‘smart links’ the RTF layer. They are not Tinderbox web links and I don’t think it is possible to simply convert them in v8.x if the link anchor text is not no an actual URL.

The issue is, I think, is that the URL is buried in the RTF. I can’t find the post we had on this a couple of months. I want to give attribution.

Some kind soul provided me with this AppleScript, which when run pulls the URL out of the RTF and returns the results to the script editor.

-- adapted from https://www.macscripter.net/viewtopic.php?pid=182034, https://macscripter.net/viewtopic.php?id=46657

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

-- get any rich texts off the clipboard
set pb to current application's NSPasteboard's generalPasteboard()
set theRichTexts to (pb's readObjectsForClasses:{current application's NSAttributedString} options:(missing value)) as list

if (count of theRichTexts) = 0 then
	display dialog "No rich text found on the clipboard" buttons {"OK"} default button 1
	error number -128
end if

set theRichText to (item 1 of theRichTexts)

-- get length so we can start from the end
set start to (theRichText's |length|()) - 1

-- make plain string copy to work on
set theString to theRichText's |string|()'s mutableCopy()

set output to return

repeat while start ≥ 0
	set {aURL, theRange} to theRichText's attribute:(current application's NSLinkAttributeName) atIndex:start effectiveRange:(reference)
	if aURL is not missing value then
		-- get linked text
		set anchorText to theString's substringWithRange:theRange
		if aURL's |scheme|()'s isEqualToString:"mailto" then -- email address
			set newLink to aURL's resourceSpecifier()
		else if anchorText's containsString:"This Site" then -- resource specifier, remove //
			set newLink to aURL's resourceSpecifier()'s substringFromIndex:2
		else -- full URL
			set newLink to aURL's absoluteString()
		end if
		set output to ((output & anchorText as text) & "::" & newLink as text) & return
	end if
	set start to (location of theRange) - 2
end repeat

return output -- to view in Script Editor Result pane

Update: Found it, it was @sumnerg (Extract Anchor and URL from pasted HTML).

Thank you all for your prompt replies.
The problem was solved by an unusual copying of the link through sharing in Notes (copy irregular fashion):

but you need such a context menu item was immediately available in the text window

Were you just trying to get the URL of one link after selecting its anchor text in the text pane?

If so, instead of string to Notes you can select the anchor text and in the menu go to Note > Make Web Link. You should then be able to copy the URL out of the popup.

Unfortunately, your way didn’t work: When you open Note->Make Web Links, the line with the link is empty:

although the link is there and if you left-click on it in the text box, then the link will be opened correctly in the browser (TinderBox Version 8.9.2 (b496))

I experienced that too. Prior to your notes explanation above, the only way I was able to get this resolved was with the AppleScript. Must have something to do with the way the link is embedded in the RTF.

Yes, these are RTF-layer only links created by the AppleFrameworks. On macOS 11 I think the context menu does show an edit link command. On my macOS 10.14.6 I don’t see one.

Ah yes, choosing Note > Make Web Link only shows the url for external links already made into Web Links, currently a manual process.

If you’re on Big Sur then selecting the anchor text (taking care to select just that text itself and no extra characters or surrounding spaces) then you should be able to control-click and choose Edit Link… in the contextual menu to get the URL.

I understand accessing external urls and general integration of of Apple’s so-called Smart Links (if I’ve got the name right) is likely to improve in upcoming versions.


Works great.