MACRO: Markdown Link Tool, v5.0

MDLT20


OVERVIEW

This macro (inspired by All-in-one URL handler by @griffman—see ACKNOWLEDGEMENTS), will paste a Markdown Link selected from a configured list. If the current object selected by the user can render rich text, the link will be entered as Rich Text; otherwise, Plain Text. The macro will end and the System Clipboard will not be affected.

Alternatively, a Markdown Link can be reformatted as HTML, Bracketed URL, or Plain URL; and the link Text can also be optionally changed.

The link, markdown or reformatted, can be written to the Clipboard* rather than pasted. Also, the URL associated with link can be opened in the default browser. Finally, this macro includes options to modify the Markdown Link text files. See the SETTINGS for more information.

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

Note: The context sensitivity, when pasting and with the Clipboard, is thanks to a JXA script provided by @ComplexPoint.


PURPOSE

This macro comes configured with more than 160 Markdown Links—mostly related to the Keyboard Maestro application and the forum. However, links can be easily deleted (individually or as a group) and others can be quickly added as well. This provides an efficient method to enter links in multiple settings. 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)

The macro Copy as Markdown Link by @ComplexPoint is a great tool compiling links.


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;* ⌥*: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;* ⌥*: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;* ⌥*+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 TRIGGER

If the trigger includes the Option Key (⌥), the macro will skip to the link management section of the macro. If the Clipboard includes a URL the macro will present a dialog to create and save a Markdown Link. If the Clipboard does not include a URL, this macro will execute the macro Copy as Markdown Link by @ComplexPoint. If a Markdown Link is successfully created, this macro will present a dialog to modify and save the link.


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.

The macro Copy as Markdown Link by @ComplexPoint is a great tool that can be used to populate the md files.

Although local_Folder can contain as any number of md files, three are supplied when this macro is downloaded:

0 Favorites.md : Some miscellaneous and recent posts and macros from the forum, and 2) some macros that I have contributed. These are provided as examples—modify this, or any 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.

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

Other md files can be optionally added to the same folder.

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. In addition, when the Clipboard includes a Markdown Link, this macro can be used manage (edit, prepend to, or append to) the files. These options can be accessed two ways:

  1. Triggering this macro with the (Control) key pressed.

  2. Selecting Edit Links from the main Prompt With List: a) pressing ⌃⇧+return, or b) pressing ⌃⇧ while clicking the OK button.


ACKNOWLEDGEMENTS

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

  • @ComplexPoint kindly permitted me to include a JXA script found in Copy Markdown as Link. See the macro OVERVIEW and Version 2 summary for more information.


TESTED WITH

• Keyboard Maestro 10.2
• Ventura beta 13.3 (22E5219e)/MacBookPro16,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.


Installation Instructions:

  • If you previously downloaded an earlier version of Markdown Link Tool, AND if you added some of your own links, then locate that version and rename it Markdown Link Tool-OLD.

  • Download and unzip the following file: Markdown Link Tool-v5.0.zip

  • Import the included macro: Markdown Link Tool. Within this macro, set the value for local_Folder.

  • Enable the macro and/or macro group if necessary.

  • Move the three text files (extension: md) to the configured folder.

  • If you added links to a older version of Markdown Link Tool, copy those links to one of the three text files.

  • Disable older versions of Markdown Link Tool.


Markdown Link Tool-v5.0.zip (51.3 KB)

Macro-image

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