zinoff
September 30, 2021, 6:58am
1
I have been using this wonderful Macro by @ComplexPoint - Copy markdown link
A single keystroke (I happen to use ⌘⌥M) to copy selected items as Markdown links from a variety of browsers and other applications.
This is a working draft of a group containing a main macro and a number of supporting sub-macros:
A main macro defining a single keystroke for use in a variety of different applications: Copy as Markdown link
various sub-macros (not stand-alone - they are called by the main one) with the bundle identifier names of specific apps.
The main macro:
can get MD li…
I wanted to make a slightly different version to create Org-mode links which use the format [[link][title]]
I have changed for the Browser URL from
Right (
`[${tab.name()}](${tab.url()})`
);
into
Right(
`[[${Tab.url()}][${tab.name()}]]`
);
And the other only line that looks like it is creating a markdown link
Right(`[${winTitle}](${maybeDocURL})`)
I have changed like this
Right(`[[${maybeDocURL}][${winTitle}]]`)
The one for the URL works and creates the link I needed, but for the app links, nada, it still returns a markdown link.
I discovered I am totally underqualified to make the changes and wonder if anyone had any idea how to go about creating links in the format [[link][title]].
/R
(edited as I submitted before I was finished writing)
Haven't taken a close look yet, but JS names are case-sensitive,
so tab.name()
vs Tab.name()
looks like one thing to fix.
(I think you need lower-case there)
OK, the code you have been trying to edit looks like it may come from one of the 35+ app-specific sub-macros in the bundle.
What you need is an additional macro:
based on a copy of the main Copy As Markdown link
macro within that bundle,
but with a different name and key-stroke
and with an edit to the JXA action labelled Copy to clipboard both as MD link and as RTF labelled hyperlink
There's a function in the code of that action called mdLinkParts
which:
takes an MD link coming in from any of the 30+ app-specific sub-macros
and returns a pair of values (labelString, urlString)
We could:
build an org-mode link from that separated pair of values, and
place it in the clipboard as plain text
You can experiment yourself, of course, but otherwise, I will aim to write an Org-mode addition to the bundle over the weekend.
In the meanwhile, here is a first sketch of a macro to add to the existing MD Link tools group.
Copy as OrgMode link.kmmacros.zip (13.6 KB)
(It isn't stand-alone, and relies on the other submacros to interact with browsers and other apps)
It includes a JS action called Copy to clipboard as OrgMode link , with the following source code:
Expand disclosure triangle to view JS Source
(() => {
"use strict";
// Rob Trew @2021
// Ver 0.1
// Orgmode [[link][label]]
// derived from KM mdLink variable
// and placed in clipboard.
ObjC.import("AppKit");
// main :: IO ()
const main = () => {
const
kme = Application("Keyboard Maestro Engine"),
kv = mdLinkParts(
kme.getvariable("mdLink")
),
orgLink = `[[${kv[1]}][${kv[0]}]]`;
return (
kme.setvariable("orgLink", {
to: orgLink
}),
copyTypedString(true)(
"public.utf8-plain-text"
)(
orgLink
)
);
};
// ---------------------- LINKS ----------------------
// copyTypedString :: Bool -> String -> String -> IO ()
const copyTypedString = blnClear =>
// public.html, public.rtf, public.utf8-plain-text
pbType => s => {
const pb = $.NSPasteboard.generalPasteboard;
return (
blnClear && pb.clearContents,
pb.setStringForType(
$(s),
$(pbType)
),
s
);
};
// mdLinkParts :: String -> (String, String)
const mdLinkParts = s => {
const ab = s.trim().split("](");
return 2 !== ab.length ? (
Tuple(s)("")
) : Tuple(ab[0].slice(1))(
ab[1].slice(0, -1)
);
};
// --------------------- GENERIC ---------------------
// Tuple (,) :: a -> b -> (a, b)
const Tuple = a =>
b => ({
type: "Tuple",
"0": a,
"1": b,
length: 2
});
return main();
})();
Update:
I've also added that draft macro to the main macro group at:
Copy as Markdown Link - Macro Library - Keyboard Maestro Discourse
zinoff
October 1, 2021, 12:32pm
5
Thank you! Works a charm. I had totally missed the second script...
1 Like