Subroutine :: Copy HTML snippet as rich text

A Keyboard Maestro subroutine for copying some HTML source code into a pasteable rich text clipboard.

Copy HTML snippet as Rich Text.kmmacros (2,7 Ko)

TEST for subroutine -- "Copy HTML snippet as rich text".kmmacros (3.7 KB)



Expand disclosure triangle to view JS source
return (() => {
    "use strict";

    ObjC.import("AppKit");

    const main = () =>
        setClipOfTextType("public.html")(
            kmvar.local_HTML
        );

    // --------------------- GENERIC ---------------------

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

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

    return main();
})();
2 Likes