Automating Markdown links with TextExpander

January 5, 2015 · 3 minutes read

Adding links to Markdown documents can be tedious at times. Especially when you’re doing it a lot or under pressure, e.g. if you’re creating show notes for your podcast while you’re recording. You’ll usually get a link from somewhere, from the chat, a guest or just by searching for it and all you want to do is insert the link with the proper title and formatting. What would you normally do? Insert the link into your document. Then open it in a new browser tab and copy the headline. Go back to your document. Insert it and fix the formatting.
There must be a better way to do this, right?

And indeed, there is. Several actually. First let me explain how I did it, then I’m going to mention a different approach created by the infamous Brett Terpstra. Depending on your workflow, you might prefer one or the other which is totally fine. Whatever works for you!

My weapon of choice is TextExpander and a little bash script. Simply because that way it will work with literally any document and app on my Mac. Whether I’m using it in Google Docs, Pages or FoldingText, it will work.

Parser snippet

Parser snippet

We’ll need two TextExpander snippet to achieve this. The first one is essentially just a script: #!/bin/bash curl -s –compressed -L –max-redirs 10 “%clipboard” | grep -o ‘.<em>’ | sed ’s/(.</em>)</title>/\1/g’ | tr -d ‘\n’</p> <p>It takes the link from your clipboard, fetches the source of the webpage and extracts the content of the title HTML element. You could also use this snippet on it’s own, if you want to.</p> <figure> <img src="https://brendamour.net/uploads/2015/01/md_link_snippet_TextExpander_hu_5cfa65b35e3d4ea7.png" class="figure-img" alt="Wrapper snippet" width="590"/> <figcaption class="figure-caption"> <p>Wrapper snippet</p> </figcaption> </figure> <p>The second element provides the markdown wrapper around the first one: <a href="%clipboard" title="%snippet:xlwtl%">%snippet:xlwtl%</a></p> <p>Some sites take a relatively long time to load, so I’d suggest to increase TextExpander’s script timeout time by executing this on the command line: osascript -e ’tell application “TextExpander” to set allowed computation time to “28”’ This will increase the time to 28s, which is plenty time for most pages.</p> <p>That’s it. Whenever you need to insert a link, all you need to do is copy it, type the magic TextExpander abbreviation into your document and a few seconds later the link appears.</p> <p>As I mentioned before, there’s another solution Brett Terpstra created: it’s called <a href="http://brettterpstra.com/projects/searchlink/">SearchLink</a> and allows you to insert search terms into your document and let the tool search for the appropriate link on its own. It’s more a solution for people who are writing articles and don’t want to interrupt their flow to look up some random link.</p> </article> <div class="pagination"> <a href="https://brendamour.net/2014/12/18/one-week-with-the-withings-aura/">« One Week With the Withings Aura</a> <a href="https://brendamour.net/2015/02/13/on-the-ipad-why-it-still-matters-a-lot-for-me/">On the iPad: Why it still matters a lot for me »</a> </div> </section> <br> </section> </main> <footer class="row middle-xs center-xs"> <div class="col-xs-3 col-md-2"><a target="_blank" rel="noopener" href="https://github.com/drallgood">GitHub</a></div> <div class="col-xs-3 col-md-2"><a target="_blank" rel="noopener" href="https://linkedin.com/in/pbrendamour">LinkedIn</a></div> <div class="col-xs-3 col-md-2"><a target="_blank" rel="noopener" href="https://brendamour.net/legal/">Legal</a></div> <div class="row center-xs"> </div> <div class="col-xs-12"> Copyright © 2025 Patrice Brend'amour. </div> </footer> <div id="modal-2219" class="modal"> <div class="modal-box"> <span class="close">×</span> <div class="modal-container"> <div class="modal-header"> <div class="modal-header-img-container" style="background-color:#FF7518"> <img data-src="https://brendamour.net/images/retrorewatch.png" class="lazyload" alt="Retro Rewatch Podcast"> </div> </div> <div class="modal-content"> <h2>Retro Rewatch</h2> <article class="entry-content"> <p>“Wow you haven’t seen that?”</p> <p>You know that show everyone thinks everyone has seen? And then you discover someone you know never saw it?</p> <p>This is the show for that. We rewatch some or all episodes of shows we have never (or not in a long time) seen.</p> </article> <h3><a href="http://retrorewatch.com">View</a></h3> </div> </div> </div> </div> <div id="modal-6a80" class="modal"> <div class="modal-box"> <span class="close">×</span> <div class="modal-container"> <div class="modal-header"> <div class="modal-header-img-container" style="background-color:#2b2b2b"> <img data-src="https://brendamour.net/images/btn.png" class="lazyload" alt="BTN Podcasts"> </div> </div> <div class="modal-content"> <h2>British Tech Network</h2> <article class="entry-content"> <p>I’m usually on the Big Show and the Mac Show</p> </article> <h3><a href="http://britishtechnetwork.com">View</a></h3> </div> </div> </div> </div> <div id="modal-926e" class="modal"> <div class="modal-box"> <span class="close">×</span> <div class="modal-container"> <div class="modal-header"> <div class="modal-header-img-container" style="background-color:#e400ff"> <img data-src="https://brendamour.net/images/foodieflashback.png" class="lazyload" alt="Foodie Flashback Podcast"> </div> </div> <div class="modal-content"> <h2>Foodie Flashback</h2> <article class="entry-content"> <p>Almost everyone has a favorite kind of food they get very nostalgic about. Be it the Mac & Cheese their grandma used to make, the fresh baked bread on a Sunday morning when the family had breakfast together, or the amazing lemonade you would make when your kids came home from school on a hot summer day. It’s the kinds of foods and beverages that immediately trigger memories when we think about them or smell them. It’s what a lot of people would also call “comfort food” bringing back warm childhood memories when we need them the most. I’d like to explore those stories with you, inviting guests from all walks of live to share their foods and their memories.</p> </article> <h3><a href="http://foodieflashback.com">View</a></h3> </div> </div> </div> </div> <div id="modal-1688" class="modal"> <div class="modal-box"> <span class="close">×</span> <div class="modal-container"> <div class="modal-header"> <div class="modal-header-img-container" style="background-color:#7ac143"> <img data-src="https://brendamour.net/images/jpasskit.png" class="lazyload" alt="jPasskit"> </div> </div> <div class="modal-content"> <h2>jPasskit</h2> <article class="entry-content"> <p>An Java™ implementation of the Apple™ PassKit Web Service</p> </article> <h3><a href="https://github.com/drallgood/jPasskit">Code</a></h3> </div> </div> </div> </div> <script src="https://brendamour.net/js/src/modal.min.b1f2588607a4108a9f5c79d672b8efc3c542e2256ffe465b5ae04fdb39713ea4.js" type="text/javascript"></script> <script src="https://brendamour.net/js/src/main.min.2eb0efba04f9d46cd2be0d81caa4f00de5b2ba8295e0fff3220fe4b02edf1e36.js" type="text/javascript"></script> </body> </html>