Copy As ...?

One or two receiving applications and web-pages are not good at making intelligent use of the Bike PasteBoard contents (Bike and OPML flavours of XML, plus utf8 plain text).

Here in a Discourse editing field for example, if I copy a line or two in Bike, and paste them here, Discourse makes a fool of itself and offers a message about uploads:

Perhaps, for such contexts, a more restrictive Copy option, like:

Edit > Copy > Copy as Plain Text ?


In the meanwhile, of course, we could write a Paste As Plain Text macro for Keyboard Maestro, perhaps preceding the Paste action with a snippet which reduces the pasteBoard content, for these less intelligent apps and webpages, from 2 * XML (Bike, OPML) + TXT to just utf8 .txt

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

    // Recopy any plain UTF8 in the clipboard,
    // dropping other formats.

    ObjC.import("AppKit");

    const main = () =>
        bindLR(
            clipTextLR()
        )(
            copyText
        );

    // ----------------------- JXA -----------------------

    // clipTextLR :: () -> Either String String
    const clipTextLR = () => (
        v => Boolean(v) && 0 < v.length ? (
            Right(v)
        ) : Left("No utf8-plain-text found in clipboard.")
    )(
        ObjC.unwrap($.NSPasteboard.generalPasteboard
            .stringForType($.NSPasteboardTypeString))
    );

    // copyText :: String -> IO String
    const copyText = s => {
        // ObjC.import("AppKit");
        const pb = $.NSPasteboard.generalPasteboard;

        return (
            pb.clearContents,
            pb.setStringForType(
                $(s),
                $.NSPasteboardTypeString
            ),
            s
        );
    };

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

    // Left :: a -> Either a b
    const Left = x => ({
        type: "Either",
        Left: x
    });

    // Right :: b -> Either a b
    const Right = x => ({
        type: "Either",
        Right: x
    });

    // bindLR (>>=) :: Either a ->
    // (a -> Either b) -> Either b
    const bindLR = m =>
        mf => m.Left ? (
            m
        ) : mf(m.Right);

    return main();
})();

Here’s a general ⌘⇧V Paste as Plain Text macro for Keyboard Maestro – it’s something which I use for pasting code, but it works in this context too:

Paste as plain text.kmmacros.zip (2.1 KB)

1 Like

Mail and TextEdit, and MS Word make slight fools of themselves too, and fail to select the utf8 component of the pasteboard

  • Mail make a bit of noise and flurry but brings nothing into the editor
  • TextEdit does a bit better, but makes everything blue and hyperlink-underlined. (It actually creates a set of hyperlinks which offer the whole pasted text as slightly implausible target url for each word)
  • MS Word brings nothing into the editor
  • MindNode pastes URL-encoded (but human-illegible) lines of text.
  • iThoughts pastes a single block of text, rather than a tree

(The Paste as Plain Text macro above works fine each case above, but perhaps a Copy As Plain Text menu-bar command in Bike might simplify ?)

Thanks to @unlocked2412 for first pointing out to me that at least one app (I think perhaps MindNode ?) was making a mess of this.

(Pasting a Bike pasteBoard into TaskPaper also seems to work a bit better with a Paste as Plain Text macro, at this stage)