2 AppleScripts to Simplify Your MarsEdit Workflow

MarsEdit is the best blogging client for the Mac. Powerful markup macros, excellent image handling and Flickr integration, a CSS enabled post preview window that renders your unpublished post exactly as it will appear on your blog and lots of other great features combine to put MarsEdit in a class of its own among blogging clients.

But while I love MarsEdit and use it daily to administer my modest blogging empire, there are aspects of the application that I hope will be improved with future releases. The biggest complaint that I have about the app is its conspicuous lack of a WYSIWYG editor. There are significant advantages to writing your posts in a purely HTML environment, and moreover MarsEdit’s preview window amply compensates for the absence of rich-text editing, but when composing long and link heavy posts in MarsEdit the excessive text-markup tags can begin to clutter your view and make it difficult to find your place when editing.

To bypass this unfortunate aspect of the application’s user interface, I have turned to writing my longer posts in TextEdit and sending them off to MarsEdit via AppleScript. A second AppleScript then simplifies the process of adding links from Safari into my posts.

The first script is a was created by adding a send TextEdit text command to a script included with MarsEdit. Here it is:

tell application "TextEdit"
	activate
	set my_text to text of document 1
	set my_title to name of document 1
end tell

tell application "MarsEdit"
	make new document
	tell document 1
		set title to my_title
		set body to my_text
	end tell
end tell

on displayErrorMessage(s)
	display dialog (s) buttons {"OK"} default button "OK" with icon caution
end displayErrorMessage

tell application "MarsEdit"

	try
		set currentWindow to document 1
	on error errorMessage
		displayErrorMessage("Can’t add paragraph tags because ¬
                no post windows are open. This script works on text in the ¬
                frontmost post window.") of me
		return
	end try

	set currentTextView to current text in currentWindow
	set numParagraphs to number of (paragraphs in currentTextView)
	set newBodyText to ""

	repeat with i from 1 to numParagraphs

		set oneParagraph to paragraph i in currentTextView

		if (oneParagraph is not "") then

			-- If already starts with <p>, don't prepend another one
			if not (oneParagraph starts with "<p>") then
				set newBodyText to newBodyText & "<p>"
			end if
			set newBodyText to newBodyText & oneParagraph

			-- If already ends with </p>, don't append another one
			if not (oneParagraph ends with "</p>") then
				set newBodyText to newBodyText & "</p>"
			end if

			set newBodyText to newBodyText & return

		else -- just add a return for empty paragraphs
			set newBodyText to newBodyText & return
		end if
	end repeat

	-- Put the new text in the window
	set (current text in document 1) to newBodyText

end tell

The above script will take the text from TextEdit and open a new blog post window with the text inside. Secondly, it adds paragraph tags to the body text at every line break (this function of the script was written by Bret Simmons, maker of the excellent NetNewsWire and original creator of MarsEdit). And lastly, it sets the title of the blog post to the title of the TextEdit document (this assumes that you’ve been saving your post in TextEdit as you write - sending unsaved text to MarsEdit will set the title of the post to “untitled”). To use the script, copy the above code into Script Editor (Applications/AppleScript/Script Editor), compile it and save it to your hard drive. Alternatively, you can download the pre-compiled script here if you don’t want to meddle with Script Editor.

In order to add links to the post I use a second AppleScript:

tell application "Safari"
	activate
	set myURL to URL of document 1
	set myName to name of document 1
end tell

tell application "MarsEdit"
	activate
	set mySelect to selected text in document 1
	set selected text in document 1 to "<a href=\"" & myURL & "\"" & " title=\"" & myName & "\">" & mySelect & "</a>"
end tell

tell application "Safari"
	close current tab of window 1
end tell

To get the most from this script, first open all of the webpages you want to link to in Safari. Next, highlight the portion of text in MarsEdit that will link to the front most page in Safari. The script will add a link to the front page in Safari and set the “title” tag to the title of the webpage. It will then close the tab, allowing you to move onto the next link without switching applications. Again for this script, if you don’t want to compile it yourself you can download it.

These two scripts have considerably increased my productivity as a blogger. I hope that they will be useful to you. If you have any suggestions about how they might be improved - or other AppleScripts for MarsEdit - leave a comment and have your say.

Download MarsEdit. It’s 29.95 after a 30 day trial.

* * *

1 Response to 2 AppleScripts to Simplify Your MarsEdit Workflow

  1. Sorry for the comment spam, but saw no other means to contact you! Please check out prMac for press release distribution, on all the latest new software releases. also, please take a peek at MacScripter too! {http://bbs.macscripter.net}

    Thanks!

Think different?