MACRO: Markdown Link Tool, v6.0

Initial Prompt With List to Select a Markdown Link


Selected Markdown Link – Optional Reformat


Selected Markdown Link – Optional Change of Link Text


Adding Markdown Links (1 of 2)


Adding Markdown Links (2 of 2)


Keyboard Maestro Version 11+ Required

Installation Instructions

  1. Download and unzip the following file.

  2. Install and activate the included macro.

  3. Move the three text files (with the md extension) to the folder specified in the variable local_Folder.

Markdown Link Tool-v6.0.zip (43.3 KB)

Documentation

PURPOSE

This macro will paste a markdown link selected from a managed list. This provides an efficient method to enter links on multiple platforms. For example:

✓ Email (rich text)

✓ Word Processors (rich text)

✓ Keyboard Maestro macro comments (rich text)

✓ Apple Notes (rich text)

✓ forum posts (plain text)

✓ text editors (plain text)

If the currently selected object can render rich text, the link will be entered as Rich Text; otherwise, Plain Text. In these cases the System Clipboard will not be affected.

Optionally, before pasting the markdown link, it can be reformatted into three other forms:

HTML

Bracketed URL

Plain URL

Also the link Text can be changed before pasting.

The markdown link, or other forms, can be alternatively written to the Clipboard* rather than pasted into the currently selected platform. Also alternatively, the URL associated with selected markdown link can be opened in the default browser.

Lastly, this macro includes options to add to and modify the configured list of markdown links. These links reside in one or more text files in a configured folder. See SETTINGS for more information.

*When the Clipboard option is selected, the macro will populate the System Clipboard with both variants/flavors, Rich Text and Plain Text. The Clipboard can subsequently be pasted based on the context of the selected platform object.

MANAGEMENT OF MARKDOWN LINKS

This macro comes supplied with more than 230 Markdown Links—mostly related to the Keyboard Maestro application and the forum. However, links for any context can be easily deleted (individually or as a group) and others can be quickly added as well.

The markdown links are stored in text files (with an md extension) that reside in a specified folder. Although the folder can contain as any number of md files, three are supplied with the macro download:

0 Favorites.md : Some miscellaneous and recent posts and macros from the forum, and some macros that I have contributed. These are provided as examples—modify this, or any of the other files, as needed.

8 Keyboard Maestro Forum.md : Macros that appear in the following forum post: Best Macro List—Macro Library. This was a curated list maintained by @JMichaelTX, who unfortunately is no longer with us. I’m not sure if this forum list will be maintained moving forward. I've added some of my personal favorites to this file.

9 Keyboard Maestro.md : Helpful links from the Keyboard Maestro Forum and the Keyboard Maestro Wiki.

To exclude the Markdown Links in any of these files: 1) rename the file by changing the extension from md to txt., or 2) delete the file.

A text editor can be used at anytime to modify the md files. The macro Copy as Markdown Link by @ComplexPoint is a great tool that can be used to populate the md files.

If the macro is triggered with the secondary hot key, the one that includes the Control key (⌃), then the macro will present options to manage the links in the configuration files. This process will be referred to as Manage Links. During normal operation, the macro will present an option to Manage Links from the initial and link form Prompt With Lists.

If Manage Links is selected (or initiated by the secondary trigger), the following will occur:

  1. The System Clipboard will be checked for a markdown link. If one is found, there will be an option to save it.

  2. If installed, the macro Copy as Markdown Link by @ComplexPoint will be spawned. That macro will attempt to create a markdown link based on the focused object within the active application. If a link is successfully created, there will be an option to save it.

  3. The markdown link from Step 1 or 2 can be prepended or appended to any of the configuration text files. Alternatively, any of the files can be edited and the link can be pasted into any file position.

  4. The folder enclosing the configuration files can be opened.

READ THE DETAILS HERE (OR JUST TRY IT OUT)

When this macro begins, the list of links will be displayed by a Prompt With List action. The first line, which is not selectable but serves as a guide, will be:

Selected link will be Pasted -or- ⇧*:* Open Link ; ⌥*:* Clipboard ; ⌥⇧*:* Alternate Form ; ⌃⇧*:* Manage Links

Thus if a link is selected and…

• No modifiers are down, the link will be pasted (assuming the focus is on an object that can accept text).

• Shift is down, the URL will be opened in the default browser.

• Option is down, the Markdown Link will be written to the System Clipboard (as Rich Text and Plain Text).

• Option+Shift are down, the macro will present a second Prompt With List with alternate forms of the link (HTML, Markdown, Bracketed URL, Plain URL) for selection.

• Control+Shift are down, the macro will present options to manage the links in the configuration files*.

When the list of forms (HTML, Markdown, Bracketed URL, Plain URL) is rendered by the second Prompt With List action, the first line, also serving as a guide, will be:

Selected form of the link will be Pasted -or- ⇧*:* Open Link ; ⌥*:* Clipboard ; ⌥⇧*:* Change Link Text ; ⌃⇧*:* Manage Links

If a link form is selected and…

• No modifiers are down, the link in the selected form will be pasted (assuming the focus is on an object that can accept text).

• Shift is down, the URL will be opened in the default browser.

• Option is down, the link in the selected form will be written to the System Clipboard (as Rich Text and Plain Text).

• Option+Shift are down (and HTML or Markdown are selected), the macro will present a dialog* that provides an option to change the link Text.

• Control+Shift are down, the macro will present options to manage the links in the configuration files.

*The link Text dialog will also include the following guide information:

The following link will be Pasted (with optional change of Link Text ) -or- ⇧*+OK click:* Open Link ; ⌥*+OK click:* Clipboard ; ⌃⇧*+OK click:* Manage Links

The alternative options, when the OK button is Clicked*, with modifiers down, are the same as described above.

*When this dialog is displayed, the modifier keys will not be honored if a press is used rather than an OK click. This seems to be a limitation with the Prompt For User Input action.

HOT KEY TRIGGERS

If the trigger includes the Control key (⌃), the macro will skip to the link management section of the macro. See more information, see MANAGEMENT OF MARKDOWN LINKS.

SETTINGS

• local_Folder : Markdown Links for this macro are stored in text files (with md file extensions) in this folder. By default, this is set to an iCloud Drive folder, but it can be changed to any folder that is writable.

• local_FavoritesFile : one md file should be designated as the Favorite File.

ACKNOWLEDGEMENTS

a) The Keyboard Maestro forum post, Using Prompt With List to modify variables on the fly and the macro within, All-in-one URL handler, by @griffman provided the inspiration for this macro! Several ideas from All-in-one URL handler are used here. The primary difference is that All-in-one URL handler does not support Markdown links.

b) @ComplexPoint kindly permitted me to include within this macro a JXA script found in Copy Markdown as Link. This script creates the rich text/plain text combo mentioned in the PURPOSE above.

TESTED WITH

• Keyboard Maestro 11.0.3
• Sonoma 14.5 (23F79)/MacBookPro18,2
• Sonoma 14.5 (23F79)/VariableMacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445

VERSION HISTORY

1.0 - Initial version

2.0
a) When pasting, if the current object selected can render rich text, the link will be entered as Rich Text; otherwise, Plain Text. When the Clipboard option is selected, the macro will populate the Clipboard with both variants, Rich Text and Plain Text. The Clipboard can subsequently be pasted based on the context of any selected object. This context sensitivity, when pasting and with the Clipboard, is thanks to a JXA script provided by @ComplexPoint.

b) Added a few Keyboard Maestro Wiki entries—MarkdownLinks Default 2; added a few more examples—MarkdownLinks User.

c) Made several refinements to dialog text, messages, and macro comments.

2.1
a) Updated parsing of text lists.

b) Other changes to increase macro speed.

3.0
a) Moved Markdown Links from text variables to configuration files: 0 Favorites.md; 8 Keyboard Maestro Forum.md; 9 Keyboard Maestro.md. Other md files can be optionally added to the same folder. Added options to: 1) navigate to the configuration folder, 2) open the configuration files, 3) Prepend to or Append to a Markdown Link in the clipboard to the configuration files.

b) Changed the primary trigger from ⌥⇧L to ⌥⇧M. Added a secondary trigger (⌃⌥⇧M) to provide direct access to the configuration files.

3.1 - Updated the information in TESTED WITH.

3.2 - When potentially updating a configuration file with the Clipboard contents, if a Markdown Link is not found, this macro executes the macro Copy as Markdown Link. This macro can build a Markdown Link to browser pages and elements for many other applications.

3.3
a) Added several new markdown links to the configuration files. This macro now includes 150+ links.

b) Corrected a few typographical errors within comments and one within a dialog.

c) Updated the information in TESTED WITH.

4.0
a) When 𝗠𝗮𝗻𝗮𝗴𝗲 𝗟𝗶𝗻𝗸𝘀 is selected, if the Clipboard contains a URL, a dialog will appear that provides an option to create and save a Markdown link. See the HOT KEY TRIGGER section above for more information.

b) When managing links, added a dialog option to skip the addition of a new link.

c) When markdown links are prepended, they are now placed below the comments at the beginning of the text files. Now using the native Write To File action, thus if KM v8.1+, the previous version of the text file will be moved to the Trash.

d) If using KM v10.2+, when markdown links are appended, using the native Append Text To File since the read-only issue has been addressed. See the comments below for more information. Also, since this native action is being used, the previous version of the text file will be moved to the Trash.

e) If using KM v10.2+, removed the Prompt With List default value (all:).

f) Fixed bugs related to the HTML, Bracketed URL, or Plain URL formats.

g) Moved the Clipboard restoration logic and CancelJustThisMacro to a single location.

h) Added several new markdown links to the configuration files. This macro now includes 160+ links.

i) Updated the information in TESTED WITH.

4.1
a) Clipboard restoration is now properly handled when the Clipboard is initially empty.

b) Deleted a few duplicate entries in 0 Favorites.md, 8 Keyboard Maestro Forum.md, and 9 Keyboard Maestro.md.

5.0
a) In the link management section of the macro, if the Clipboard includes a URL two dialog options were added: Skip and Clear CB and Skip. When either option is selected, the macro continues and spawns Copy as Markdown Link, a macro by @ComplexPoint to potentially create a Markdown Link from the current application context. Previous versions only included two options: OK (to process the Clipboard URL) and Skip (to open the link files folder). In this version, the previous Skip button has been changed to Folder.

b) Improved error checking and more information to the dialogs that appear during analysis of URLs/Markdown Links found in the Clipboard or created by Copy as Markdown Link.

c) Improved the readability of the main Prompt With Lists by adding :point_right:t6: to the entries that contain information regarding alternative actions that can be summoned using modifier keys.

d) Improved readability of the Prompt With List used to select the mode for updating links files.

e) Simplified the CSS Style generation, by moving style comments to a Comment action above local_Style.

f) Changed from AppleScript to Set Variable to Text to delete the global variables used in the JXA that creates the two-variant clipboard.

g) Changed the settings to use local variables. Previously global variables were used and the values were then copied to local variables. (This seemed like a good idea, but it really added unnecessary complication.)

h) Streamlined some of the macro logic.

i) Added several new markdown links to the configuration files. This macro now includes 175+ links.

j) Updated the information in TESTED WITH.

6.0
a) Keyboard Maestro v11+ is now required.

b) The Markdown Links can now be exported to a JSON file. This is initiated by launching the macro from the Keyboard Maestro editor with the Command Key (⌘) down. The file, MLT.json will be written to the folder defined by local_Folder. I use this exported file to import into the application Anybox. (The JSON is structured to import the links into the MLT Anybox Collection.) With that information in Anybox, on iOS, I created a shortcut named Markdown Link Tool that uses Choose from List shortcut action. The shortcut then updates the iOS Clipboard with the selected Markdown Link.

c) Running Copy Markdown as Link is done using AppleScript. This allows the UUID to be a variable which gives some flexibility. The UUID included by default refers to the 2024-03-16 version downloaded from the GitHub site: GitHub - RobTrew/copy-as-md-link: macOS Keyboard Maestro macro group – single keystroke to copy MD links from different applications

d) Optimized the method to compile and present the saved links, thus the initial Prompt With List appears more quickly.

e) Modified the logic to significantly improve performance.

f) Removed the header comment to conserve space in the Keyboard Maestro plist. The header information is now available only on the Keyboard Maestro forum.


Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 14.5 (23F79)
  • Keyboard Maestro v11.0.3
5 Likes

Nice! If I used Markdown at all, I'd find this invaluable, I imagine :).

-rob.

2 Likes

And I did actually learn something very useful from your version: How to redisplay the input box if a user selects one of the dividers. That solution—use a repeat loop until the response variable is not empty, and set it to empty for any of the dividers—is brilliant in its simplicity!

-rob.

3 Likes

Hi @griffman. If I may, I have a suggestion...

Even though you don't use Markdown Links now, consider using this macro. As I see it, here would be the advantages:

  • When generating your HTML links, the Markdown Link Text is used as the default for the Link Text.
  • When using the forum, it really handy to have the Markdown Links available for quick insertion.

The small downside is that you need to populate the macro with your Markdown Links. The good news is that this is extremely easy with Copy as Markdown Link by @ComplexPoint.


How's that for being bold? The guy that stole several of your ideas is asking you to jump on board with his version of the macro. :rofl:

1 Like

I probably stole that from someone else? :rofl: I'm to the age where I don't necessarily remember. When I do, however, I try hard to give due credit.

But as I'm sure you know, one of the great benefits of Keyboard Maestro is the ability to borrow ideas from others!

Well, here's the thing…I actually dislike using Markdown, and go out of my way to not use it whenever possible :). I've been writing HTML for so long that it's second nature, and I don't have to remember two different syntaxes; if I'm writing for the web, I'm writing in HTML. It's just easier for me, and I don't see the upside in learning another syntax at this point.

True story: One of my prior employers (briefly) required us to submit everything in Markdown format. I still wrote in HTML, then ran it through a converter and sent it in :).

-rob.

1 Like

That's a funny story, Rob.

Okay, I give! But the irony of your day job email address: rob@manytricks.com :rofl:

It's our apps that do many tricks, not us :).

-rob.

Haha, I think with just a little work you could come up with a catchy company slogan! :grinning:

2 Likes

Markdown Link Tool has been updated to Version 2.0.

  • When pasting, if the current object selected can render rich text, the link will be entered as Rich Text; otherwise, Plain Text. When the Clipboard option is selected, the macro will populate the Clipboard with both variants, Rich Text and Plain Text. The Clipboard can subsequently be pasted based on the context of any selected object. This context sensitivity, when pasting and with the Clipboard, is thanks to a JXA script provided by @ComplexPoint.

  • Added a few Keyboard Maestro Wiki entries—MarkdownLinks Default 2; added a few more examples—MarkdownLinks User.

  • Made several refinements to dialog text, messages, and macro comments.

Markdown Link Tool has been updated to Version 2.1.

  • Updated parsing of text lists.
  • Other changes to increase macro speed.

HTML <a> tags ought to work in Markdown. So you could continue to use them.

I say that as a big fan of Markdown.

I wouldn't want to maintain a document that someone had written in HTML. I do maintain documents collaboratively written with others in Markdown. (Not least presentations written in it and put through mdpre/md2pptx.)

Martin:

I don't write with others, I don't maintain documents written by others, and I have zero interest or need to use Markdown. My HTML writing is directly in blog posts, for web pages, or for KM macros, and I'm 100% comfortable using HTML in those situations.

For me, it makes no sense to work with a subset of the entire language, in a different dialect as it were, when I can just use the language itself. I know that's not true of others, and I know many rely on Markdown to make it much easier to work on shared documents with people who don't know HTML. None of that applies to me, though.

-rob.

1 Like

@_jims I just came across this and at first thought I wouldn’t have any use for it. I was wrong!

I just downloaded it and immediately saw its utility. I made one adjustment that makes it a little easier to use this on multiple computers. I have the variables populated from text files saved in my Dropbox that way I don't have to worry about updating the variables in KM Editor on each device. This way I can just edit the text files when I want to make updates to my list.

Thanks again for sharing!

Hi @cdthomer. Glad you find it useful.

So far, I've been using it primarily when participating on forums—and lately this has been my favorite one. :grinning:

if you are doing the same, you might also find this macro useful: Augment or Filter Text

Nice enhancement—thanks for sharing! I'll likely make a similar change on my personal copy (I'll use iCloud Drive, however), but as you likely know, a feature that includes interaction with the file system introduces some implementation friction for newcomers, particularly when Dropbox is introduced. On the other hand, pros like you can easily make an enhancement like you have shared.

With that said, I'll give this some more thought. Maybe I could make it an option to use files.

Thanks again, for sharing your feedback.

If you haven't done it already, you could modify the Edit Me logic to open the folder that contains these files.

On this particular detail, you might want to check out Log It. With that macro, there's an option to open and enclosing folder or a specific file. The revised Edit Me could open the folder or optionally open the file associated with the MarkdownLinks User variable.


Responding to feedback by @cdthomer, I've updated Markdown Link Tool to Version 3.0.

  • Moved Markdown Links from text variables to configuration files: 0 Favorites.md; 8 Keyboard Maestro Forum.md; 9 Keyboard Maestro.md. Other md files can be optionally added to the same folder. Added options to: 1) navigate to the configuration folder, 2) open the configuration files, 3) Prepend to or Append to a Markdown Link in the clipboard to the configuration files.

  • Changed the primary trigger from ⌥⇧L to ⌥⇧M. Added a secondary trigger (⌃⌥⇧M) to provide direct access to the configuration files.

1 Like

This is great Jim, I have really come to like this macro and it has become one of my most frequently used ones throughout my day.

Question: when I made those modifications to my personal copy I saved the files as txt files, what are the advantages to using md files?

EDIT: a followup! I made a slight modification to this portion of the macro to automatically populate the Text field with the front window's name... because I am that lazy :laughing:

1 Like

Thanks, @cdthomer. I appreciate the feedback. Glad you find this macro useful.

Many text editors (e.g., BBEdit) will apply proper Markdown syntax coloring/highlighting for files with an md extension.

That's a great idea, but when testing with Safari, I've noticed an issue. If I go to the search/URL bar (using File > Open Location—⌘L), then Copy—⌘C, and run the macro %WindowName%1% is empty (at least, most of the time). However, if I click onto the body of the web page after ⌘C and run then macro, %WindowName%1% includes the web page title. I do not see this same issue with Chrome.

After discovering this issue, I replaced %WindowName%1% with %SafariTitle% and that seems to be populated as expected. So my questions to you, @cdthomer :

  • Did you add %WindowName%1% to get a web page title?
  • If yes, what browser have you been using?

Based on you suggestion and my testing, here's what I'm thinking of adding to the next version:

Proposed modification-image

Keyboard Maestro Export


Also, as I was working through this, if the URL is empty and Safari or Chrome is running, I was thinking, why not I prompt to populate with one, the other, or both of the following:

  • [%SafariTitle%][%SafariURL%]
  • [%ChromeTitle%][%ChromeURL%]

So considering your feedback and this addition, here's how the whole section would change:

Macro section-image

Whew, that's a lot of work to get one Markdown link!

After I hear back from you, @cdthomer, I'll share an updated version of the macro.

Hey Jim, yes I used %WindowName%1% to get the title, and I noticed the same issue on occasion.
I use Safari only.

I like the changes you proposed! I’ll keep an eye out for the update!

@cdthomer, thanks for the quick reply.

I've been continuing to test since my previous post. Even though it seems to work, it can be slow under some circumstances and I'm not keen on the complexity that it adds.

Here's an alternative approach that I'm strongly considering for the next version:

Alternative approach-image

1 Like