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