You can never own too many text editors. Okay, I can never own too many text editors. I recently splurged on BBEdit, the venerable HTML and text editor for the Mac. There’s something pleasurable about tweaking BBEdit to use it as a blogging tool. One such tool I hacked together is an AppleScript to send a post from BBEdit to MarsEdit for final publishing. Here’s how you do it.
Paste the following text into the Script Editor app on your Mac (warning: I’m no coder, and did this through trial and error based on other scripts, so this script probably contains some completely unnecessary code):
on run
tell application "BBEdit" to set theFile to file of document 1
set appleScriptPath to theFile as text
set currentURL to POSIX path of appleScriptPath
set currentURL to ("file://" & currentURL)
tell application "MarsEdit"
activate
make new document
tell document 1
set body to theFile
end tell
activate
end tell
end run
Compile then save the AppleScript. For the final step, you need to move this AppleScript to the BBEdit scripts folder. Get there by clicking on the Scripts icon near the far right of the BBEdit menu, and choosing “Open Scripts Folder.”
Once the AppleScript is in place, it will appear at the bottom of the dropdown when you click on the Scripts icon. Selecting it will take the text in BBEdit, and open it in a new MarsEdit document. I wrote the initial draft of this post in BBEdit, before using the AppleScript to send it to MarsEdit for final edits, adding of the image, assigning tags and categories, and sending off to WordPress.
Ryan Dotson says:
I think my most used script when writing blog posts is ‘Safari Tabs to Markdown References List’ which adapts an old Brett Terpstra script that collects all the URLs and titles of the active Safari window and inserts them into BBEdit as a Markdown reference list. This particular version uses a feature from BBEdit’s Clippings that allows you to press tab to cycle through the reference list to set its identifier.
I’ve had it for yonks, but after a little digging I think I found the definitive source: http://ranea.org/bbedit-markdown.html
February 17, 2019 — 8:32 am
Evan Kline says:
I’ll have to check that one out. I’m using a similar one, but for some reason it seems to grab links to not just open tabs, but also either recently closed tabs, or maybe it’s tabs from other devices. Either way, it gives me more than I need, so maybe the one you shared will work better.
February 17, 2019 — 8:39 am
smokey says:
@40Tech Nice work there :-) There’s not so much extra code as doing everything a long way, which is totally normal when getting started with AppleScript. Neat to see that MarsEdit can just read files on disk into post bodies, too…
Here’s a version that uses a different (and in my mind, more AppleScript-y) approach (with the caveat I don’t have MarsEdit, so I can’t vouch for whether its
make new document
command works as “normal” in AppleScript, but you could always make the document like you do in your script, then set the body topostText
after, using 2 steps, if needed):on run
tell application "BBEdit" to set postText ¬
to contents of document 1
tell application "MarsEdit" to make new document ¬
with properties {body:postText}
end run
(The
¬
is a continuation character to allow you to hard-wrap long lines without breaking the script, mostly used when you’re going to be posting a script somewhere you don’t have control over line-length and wrapping.)Er, I guess you still want an
activate
in there for MarsEdit, too, to bring it to the front in order finish up posting manually. But welcome to the world of AppleScript, and hope this gives you some new avenues to explore :-)February 18, 2019 — 2:33 am
40Tech says:
@smokey Thank you! I will give that a try, and see how it works. I know just enough to be dangerous at this point.
February 18, 2019 — 7:57 am