Copy as Markdown Link

Generally the UUID of macros that are exported will be retained when they are imported, presuming they don't exist already (which would normally only happen if you re-import the same macros multiple times).

However if there is any conflicts, then Keyboard Maestro will create replacement UUIDs (and internal to that import, and macro references will be updated for the new UUIDs, the code is actually painfully complicated).

Perhaps make a way to read the UUIDs which only needs to be done once (or after changes).

1 Like

First update to a new version (in original post) which now:

fetches sub-macro UUIDs from a JSON dictionary held in a KM variable.

Keyboard Maestro.app now is only needed when first generating that dictionary, or regenerating it after new sub-macros are added.

For those who have wanted to keep Keyboard Maestro.app closed, and were discomforted by seeing it open to select submacros, should now find that this only happens on the first run (after installation of this version), and not thereafter, unless additional sub-macros are installed.

The speed of MD Link copying may also have increased, for many applications.

Test reports welcome.

So Far So Good! everything works perfectly! if anything comes up I will most definitely bring it up here. such a great update! thank you very much! :slight_smile:

1 Like

@ComplexPoint, this macro is incredibly useful. Thanks so much for sharing it and updating it periodically.

I have HoudahSpot, but through a Setapp subscription. When I run Copy as Markdown Link, a dialog appears that includes the following: Consider adding a macro named 'com.houdah.HoudahSpot-setapp' to the KM Group 'MD link tools'.

I copied com.houdah.HoudahSpot4 and renamed the copy com.houdah.HoudahSpot-setapp, but the dialog still appears. Is this because the Setapp About reports: Version 6.0.4 (Build setapp-580). Or am I missing something else?

Thanks!

I'm not a setapp user, but I'll see if I can temporarily download an evaluation copy and see what is going on there.

That one is essentially a very simple macro (a value saved to the KM variable mdLink from:

(() => {
    'use strict';

    // Rob Trew @2020
    
    return Application('HoudahSpot')
        .selection()
        .map(
            x => `[${x.name()}]` + (
                `(${encodeURI('file://' + x.path())})`
            )
        )
        .join('\n');
})();

What happens if you run that script from Script Editor ? (with the language selector at top left set to JavaScript)

Thanks for the quick reply.

It shows the file selected in HoudahSpot, so that looks good.

Aside from copying and renaming the sub-macro, is there something else I need to change. I see above...

Does that occur automatically or do I need to update the JSON manually?

Well caught – I think that's exactly the issue. Two options:

  • Manually clear the uuidsForMDLink variable, and then run the macro again. It should be fractionally slower the first time, while it rebuilds the map of UUIDS, and then faster thereafter.
  • Or, download the latest version of the Copy As MD Link macro group (top of this thread or from Github), and run a utility macro which it now contains - Update map from bundleIDs to KM UUIDs (after new sub-macro added)

That macro should rebuild the value of the uuidsForMDLink variable, and show you its contents.

Let me know if that seems to work, and I'll update the documentation.

( I think you may be the first to add a sub-macro of your own since the switch to a uuid map )

Worked perfectly -- thanks for the update!

1 Like

Hi Rob,
This is a remarkably useful tool. Any chance you could add support for Mellel and Mailmate?
Yours,
Maurice

Sorry-- I see that Mailmate does work! Mea culpa. Mellel though isn't responding as nicely.

It seems to be working here with Mellel – copying an MD link to the file of the front document, which does have to have been saved.

(we can't derive a file reference from an untitled new document which has never been saved)

Testing here on Big Sur, with Mellel 5 – does that differ from your context ?

Hi Rob,
Same setup here.
I'm getting an error message of "Window " of: com.redlex.mellel5
may not be a document window.
Thanks for the quick response!
Yours,
Maurice

Hi Maurice, I can get that result if the selected window (in Mellel)

  • isn't a document window
  • or doesn't contain a file that has been saved.

is your cursor in a saved Mellel document ?

@ComplexPoint Thanks for this incredibly useful macro. I would like to ask you if it would be possible to add a sub-macro for Newton Mail. I get the error when I use the shortcut in the app. Window '' of:
com.CloudMagic.MacMail
may not be a document window.

Not an application that I personally use.

Does it have a scripting dictionary, or a copy as link menu item ?


UPDATE

I did take a quick look, and Newton does have a Copy as Link ⇧L for the url itself but I can't immediately see a route to scripted capture of the name of an email item.

There's no scripting dictionary, and Newton windows bear the name of the email service rather than the title of a piece of mail.

More generally, it turns out that Newton is only an Electron app (a thin wrapper around a web page) rather than a full app which uses macOS native controls (beyond the menu and the basic window buttons).

(i.e. the name of an email is not accessible to macOS UI scripting)

The ⇧L on its own may be the thing for you to use, in practice.

1 Like

I know there is ⇧L but it opens the mail in webpage rather than the app so I cannot read through other related emails. That’s why I wanted to ask if another way is possible. I remapped the ⇧L in Newton to ⌘⌥M and disabled the macro in Newton. So at least now I use the same shortcut for link copying. Thanks again for the macro and your quick-detailed response!

1 Like

Updated above to allow for pasting RTF labelled hyperlinks into rich text editors.

In addition to the plain text MD Link, the macro now also copies RTF to the clipboard, which will be used when pasting into rich text (rather than plain text) editors.

Pasting into plain text editors and fields works as before, yielding a [label](url) Markdown version of the link.

2 Likes

Updated above to add:

  • com.sonnysoftware.bookends2 (Bookends version 14)
  • Copy as OrgMode Link (a draft of an additional macro, which depends on the same sub-macros as the existing Copy as Markdown Link)
1 Like

The copy on Github has been updated to allow for multiple RTF and OrgMode links when several items are selected (in relevant applications, like the Finder, for example)

(Copying multiple MD links was already possible in these contexts)

(Discourse forum editing rights for the copy at the top of this thread have now expired)

Updated (Github copy, as in previous post) to add:

  • com.omnigroup.OmniOutliner5

In the case of OmniOutliner, in addition to a link to the active document, the macro also copies MD (or RTF, OrgMode) links to any specific rows that are selected in the GUI.

(Note, OmniOutliner links to specific rows require that the document itself is already open, so a typical pattern would be to click first – if necessary – on the document link, and then to make use of any links to particular rows).