Posting text from BBEdit to MarsEdit with AppleScript

Hi everyone! I was able to get a script that takes Markdown from BBEdit and puts it into MarsEdit for publishing, but I want to polish it up a bit and it’s giving me a little trouble. Using a script I found and changed for my own purposes, I was able to get it to the point where it pastes the contents of the BBEdit window as the body of the post in Mars Edit, but I want to make it so that I can set the title to be the first line of the Markdown text. Does anyone have any advice on how to make that happen?

Here is my GitHub link.

Hi michaelm! Long time no see. Welcome back to the forum.

I am very far from an AppleScript expert, but I looked at your AppleScript and compared it to other things that I saw online and it looked right to me, so whatever the issue is, it’s not obvious to me either, for what it’s worth.

I would recommend sending an email to Red Sweater Support (email address can be found at that link). Daniel is usually extremely responsive and helpful to support inquiries.

Also, when posting AppleScript to GitHub, especially to a gist, or to Discourse, just copy/paste from the editor window and put three ` characters on a separate line before the first line of the code block and another line of three ` characters after the last line of your code block, and it will look like this:

-- Set some global values to be used later in the script
property markdownloc : "/usr/local/bin/multimarkdown"
on translate_line_breaks(str)
	set AppleScript's text item delimiters to {ASCII character 13}
	set _lines to every text item of str
	set AppleScript's text item delimiters to {ASCII character 10}
	set str to _lines as text
	set AppleScript's text item delimiters to {}
	return str
end translate_line_breaks
-- Handler for when the script is called from the BBEdit scripts menu
on run
	tell application "BBEdit"
		set mdSource to contents of text window 1 as Unicode text
	end tell
	set mdSource to translate_line_breaks(mdSource)
	tell application "MarsEdit"
		make new document
		tell document 1
			set body to mdSource
			set title to Unicode text
		end tell
		activate
	end tell
end run

If you do have to upload an AppleScript file to Github, save it as text as shown here:

The file extension will be .applescript instead of .scpt but the file format will be plain text, which makes it much easier to use git for tracking changes, and it will be easier for others to see your code on Github because they won’t have to download a file, it will display right on the site as text.

I hope this helps. Please let us know if you find the solution! I use MarsEdit myself and I would be curious to know how this works.

Wow, I can tell I’ve been busy for the last month or so. I haven’t had time to write or even look into this. I’ll give it a go. Thanks TJ!

1 Like