Extract Anchor and URL from pasted HTML

Apologies if I misunderstood end intent here. I thought this referred to links rather that RTFD as a whole.

As to link storage, I think we are on the same page. I was being under-specific. I’ve amended my post above and pointed to the only documentation I know of on this area of the app. In aTbRef it variously refers to v6 or v7. Essentially this model is correct up to v8 except with regards to things like window and tab state. As the latter (saved tabs) is changing for v9, I’ll probably update the part post-launch as it’s a long task of black-box testing to both find stored versions of all states and then to diagnose their mapping to actual settings.

Yes! I’d totally agree that making the styled text version of the note available to scripting would be useful (if possible without a lot of engineering cost.)

The links aspect has become confusing simply due to (past) issues with detecting/adopting links pasted or generated in the RTFD layer.

The linkbase approach may seem alien to those educated on the Web, but the linkbase is a stronger and more classically hypertext approach. In principle it allows different—or no—linkbase to be applied to a given note. Indeed in Microcosm the user was able to apply numerous discrete linkbases to the same corpus and by altering the linkbase stack order influence from with link base a potential link might be supplied. The closest we get in Tinderbox is to link the same notes with multiple links of differing link types, which allows us different semantically defined trails through our hypertext (document).

1 Like

Thank you for the pointers on the “linkbase”!

Confusion as to aim is understandable as the discussion started with a question about how to extract links from the rtf. When I later commented in passing how easy it was to get values out of Tinderbox by script, except for rtf, @Pete broadened the discussion by asking for the ability to pass an attributed string into Tinderbox.

That got me learning about attributed strings and such, culminating in the (latest) script above demonstrating that it is not too hard to get rtf out of Tinderbox and into an attributed string without manually going through the clipboard. The flow: Encoded rftd from between the rtfd tags → unencoded rtfd → unencoded string rtf → attributed string. And then from attributed string to wherever.

That scripting flow already works. Here on the left is the Tinderbox text pane and on the right the result of the script as displayed in Script Debugger. (Script Editor can’t display an attributed string, but it’s there.)

The styling, including colors and fonts (mostly), exports “automatically.” No html coding and css. Potentially useful!

But scripting would be much simplified by being able to get the encoded rtfd as one would the value of an attribute, rather than mess with querying the xml. And from a scripting point of view it is a pity to lose an external link from the rtf after choosing Make Web Link... There might be an advantage to leaving external links in the rtfd when they are recorded in the “linkbase” (so they’ll export via native Tinderbox export to html/markdown and also via script to attributed string.)

Going the other way as @Pete suggested–from attributed string into Tinderbox–I’m not so sure. I was thinking perhaps the flow could be attributed string → base64 encoding → rtf → rtfd. Not sure, though, of the implications of setting the value of the rtfd. Perhaps @eastgate can comment in due course.

Nope; that’s not going to work. I think I might see a way to do this, but not before Tinderbox 9 is sorted out.

If you know of any decent documentation on Applescript’s handling of NSAttributedString, that would be nice to have.

When it comes to AppleScript expectations can vary on what constitutes “decent documentation”! But after educating myself a little more I find the documentation is better than I originally thought it might be.

NSAttributedString and its methods and instance methods are of course well documented. So the trick is to understand how AppleScript calls them. That is done via AppleScriptObjC, or AsObjC for short. A quick explanation of AsObjC appears here.

By far the best resource to understand AsObjC is Shane Stanley’s Everyday AppleScriptObjC e-book. It turns out that the weird-looking possessive is simply telling AsObjC to call an instance method.

The book includes lots of examples, including explanations of how to interpret the Cocoa documentation well enough to get code working in AsObjC. NSString is covered extensively. I couldn’t find anything specifically on NSAttributedString, but the approach is the same, calling different methods.

There are NSAttributedString examples in the Late Night Software forums (Script Debugger, which Shane developed), including here and here, and on macscripter.net. And, of course, there are a few AsObjC examples in the Tinderbox forum by @ComplexPoint and @Pete, and above in this thread.

Looking forward to Tinderbox 9! (I hope it will let me copy rtf out of the text pane, or File > Export > As Text > RTF) with external links still “live” after I have converted them via Note > Make Web Link… Right now, in 8.9.2, they appear in the “linkbase” but disappear from the rtf.)

1 Like