More Fun With Markdown Text Services

I couldn’t resist. Here are some more generic solutions for text processing via the Services Menu. Create an Automator Services project that accepts text and replaces the selection with the result as shown. Add a “Run AppleScript” step to the workflow. Automator Script Here’s the AppleScript to convert a selection of text to a bulleted Markdown list:

on run {input, parameters}
    set inputString to input as string
    set newList to {}
    set myString to paragraphs of inputString
    repeat with myItem in myString
        set NewItem to "- " & myItem
        set end of newList to NewItem
    end repeat
    set AppleScript's text item delimiters to "
"

    set combinedList to newList as text

    return combinedList
end run

Once the service is installed, you can select a series of text lines like this:

item 1
item 2
item 3

and turn it into a bulleted Markdown list like this:

- item 1
- item 2
- item 3

Here’s the AppleScript to generate a numbered list

on run {input, parameters}
    set currentCount to 1
    set inputString to input as string
    set newList to {}
    set myString to paragraphs of inputString
    repeat with myItem in myString
        set NewItem to currentCount & ". " & myItem as string
        set end of newList to NewItem
        set currentCount to currentCount + 1
    end repeat
    set AppleScript's text item delimiters to "
"

    set combinedList to newList as text

    return combinedList
end run

And finally, here’s one that takes a series of URL’s and converts them into a set of link references. This is useful if you gather a bunch of reference links before writing and you want to convert them all into a series of references. The reference titles are automatically incremented by the script. I added one additional step to this workflow to extract the URL’s from the text.   Automator Script

 on run {input, parameters}
    set currentCount to 1
    set newList to {}

    repeat with myUrl in input
        set NewItem to "[Link_" & currentCount & "]: " & myUrl as string
        set end of newList to NewItem
        set currentCount to currentCount + 1
    end repeat
    set AppleScript's text item delimiters to "
"

    set combinedList to newList as text

    return combinedList
end run

This will take a series of links like this:

www.apple.com
www.google.com
www.omnigroup.com

and convert it into a list of link references like this:

[link_1]:  www.apple.com
[link_2]: www.google.com
[link_3]: www.omnigroup.com

Leave a comment

You must be logged in to post a comment.