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:
-
Triggering this macro with the ⌃(Control) key pressed.
-
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 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)