Forcing Named Clipboard to only accept plain text?

I would like to create a macro that copies a URL from an app's menu command (Agenda) and grabs the UUID from that URL. When I select the menu command in the app and paste it into a text field, I get the following:

agenda://note/D1BC0274-50D9-45B4-9222-D5EE79D42782

However, in Keyboard Maestro, what ends up on the clipboard is the title of the note as a hyperlink. When I go into the clipboard switcher, I can select the text and "edit hyperlink."

So, if I go into the clipboard switcher, select the Named Clipboard, and choose "Set Clipboard to Plain", then re-run the macro, the url correctly shows up in the clipboard for me to work with. Unfortunately, if I run the macro again, the clipboard goes back to accepting the hyperlinked title instead.

So: is there a way to designate a Named Clipboard as plain forever?

I have tried the trick from @peternlewis in this post, but what that does is take the title of the note and remove the hyperlink. What I need is only the URL, which seems to be stripped out through this method.

Change Dates.kmmacros (8.6 KB)

Is there some special reason you are using a KM Named Clipboard?
If the data you want is plain text, then it is almost always better to save it to a KM Variable. If you save it as a Global Variable then it will be available to all macros, and even across Mac restarts (just like files).

So, instead of this:

use this:

image

That should set the KM Variable "Agenda_URL" to the URL:
agenda://note/D1BC0274-50D9-45B4-9222-D5EE79D42782

You will need to adjust your Macro to use this KM Variable, rather than the Named Clipboard.

BTW, just to be clear on terms, what you want is the "URL", not the "UUID".

What you are seeing on the clipboard is usually referred to as a "hyperlink", like this:
Agenda - Date-focused Note Taking

Questions?

My impression is that perhaps Derek does actually want to get the UUID – by extracting that component from the URL.

Not sure of the exact context, but given that Agenda places several data formats in the clipboard on Edit > Copy As > Agenda Link, it may conceivably be helpful to extract just the UTF8 content, perhaps with a JavaScript for Automation snippet along the lines of:

(() => {
    'use strict';
    
    ObjC.import('AppKit');

    // clipboardText :: IO () -> String
    const clipboardText = () =>
        // Any plain text in the clipboard.
        ObjC.unwrap(
            $.NSString.alloc.initWithDataEncoding(
                $.NSPasteboard.generalPasteboard
                .dataForType($.NSPasteboardTypeString),
                $.NSUTF8StringEncoding
            )
        );
        
    return clipboardText()
})();
1 Like

Hi Rob -- You're right, I do want the UUID, so that I can feed that back into another x-callback-url command (no AppleScript or Javascript support for Agenda that I can see). @JMichaelTX's solution above worked for me--I have used KM a bunch, but I'm not really sure about all these various text formats and how to get around them. Thanks for the JavaScript solution too though, that might come in handy in another issue.

1 Like