More Fun With Markdown Text Services

August 17, 2011 by Gabe | [mmd] |

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: [cc lang="applescript"] 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[/cc] Once the service is installed, you can select a series of text lines like this: [cc]item 1 item 2 item 3[/cc] and turn it into a bulleted Markdown list like this: [cc]- item 1 - item 2 - item 3[/cc] Here's the AppleScript to generate a numbered list [cc lang="applescript"]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[/cc] 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

[cc lang="applescript"] 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[/cc]

This will take a series of links like this:

[cc]www.apple.com www.google.com www.omnigroup.com[/cc] and convert it into a list of link references like this: [cc][link_1]:  www.apple.com

blog comments powered by Disqus