Accessing rich text attributes with AppleScript

Is it currently possible to manipulate attributes with AppleScript? I want to grab a URL and title from a Safari tab and create a row in a Bike document that has the URL applied as a rich text link.

I personally use this:

Copy as Markdown Link - Macro Library - Keyboard Maestro Discourse

(or Code > Download zip here: RobTrew/copy-as-md-link: macOS Keyboard Maestro macro group – single keystroke to copy MD links from different applications.)

to paste a (label, url) pair as a blue link in Bike.

(The macro creates plain text, RTF, and formatted Bike clipboard content)


More generally, the AppleScript route is by reading and writing the

htmlContent of row

property, which returns and expects text with HTML formatting tags.

Selecting the blue line below:

( url with label copied from Safari and pasted into Bike by that Keyboard Maestro macro)

and evaluating the AppleScript snippet

tell application "Bike"
    tell selection row of front document
        html content
    end tell
end tell

yields:

<p>
  <a href=\"https://support.hogbaysoftware.com/t/accessing-rich-text-attributes-with-applescript/5021\">Accessing rich text attributes with AppleScript - Bike - Hog Bay Software Support</a>
</p>

To create formatted content through AppleScript, you prepare the HTML for a row (between <p> .... </p> start and end), and then assign the the value of the html string to the htmlContent property of the row.

PS if you want to place formatted Bike content in the clipboard, you will need to use the AppleScript interface to ObjC classes – particularly this one:

NSPasteboard | Apple Developer Documentation

(I find it easier to do all this in the JavaScript flavour of osascript, and you will see JS versions of how to do this in the KM Macro above)

e.g.

Expand disclosure triangle to view JS Source
// Requires a preliminary incantation:
// `ObjC.import("AppKit")`

// setClipOfTextType :: String -> String -> IO String
const setClipOfTextType = utiOrBundleID =>
    txt => {
        const pb = $.NSPasteboard.generalPasteboard;

        return (
            pb.clearContents,
            pb.setStringForType(
                $(txt),
                utiOrBundleID
            ),
            txt
        );
    };

( The Bike clipboard type identifier is com.hogbaysoftware.bike.xml, and, of course, the string submitted has to constitute well-formed Bike XML)

@complexpoint That got me where I need to be. Thank you!