Copy as Markdown Link

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).

Hi @ComplexPoint,

Thanks for sharing the macro. I just downloaded it. Can you add Vivaldi and Microsoft Edge browser support to the list?
Or can you advise me how to add them myself?

I don't have or use those browsers myself, but if (unlike Firefox) they do provide osascript (AppleScript / JavaScript) interfaces then the ingredients would be:

  • a sub-macro with the application's bundle id as its name,
  • which returns its value (a markdown link string) to the variable "mdString"

If they are not scriptable (or their script interface doesn't give access to the url and title of the active page), then they are essentially out of range for this kind of macro.


UPDATE

I've added support for the Vivaldi and Microsoft Edge browsers to the Github copy at:

RobTrew/copy-as-md-link

(It turned out that they use Chromium code for osascript access to the url and page name, so a small edit to the main macros – Copy as MD and Copy as OrgMode– was enough, without any sub-macros specific to additional bundle ids)

Just downloaded and reinstalled it. It's working now. Thanks!

1 Like

Apologies in advance - the thread is nearly 80 items long, my question may have been answered on the way.

I maybe the laziest person ever. Currently I'm using this script to get links out of Safari and DevonThink. And it's DevonThink that is funky. I'm getting extra references to PDF page numbers: Tips for Developing Survey instruments/questionnaires p0 of 15

I suspect most people won't care that we're getting a link to p0 of 15. In my case all I want to do is link notes in a tool like TheBrain/Obsidian back to a document in DevonThink. Is there an elegant fix?

1 Like