Last active
June 14, 2026 20:29
-
-
Save jeredb/ddf69d6a94d9ba51b1750a480b2a0f70 to your computer and use it in GitHub Desktop.
An adapted Applescript to export markdowns from
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Original details and explanation: | |
| -- https://daringfireball.net/2026/03/applescript_save_marsedit_document_to_text_file | |
| -- Modification details: | |
| -- https://jeredb.com/posts/exporting-drafts-from-microblog-via-marsedit-thanks-to-john-gruber | |
| tell application "MarsEdit" | |
| set _blog to blog 1 | |
| set _posts to every post of _blog | |
| set _output_posix to "/Users/jeredb/Documents/Blog/" | |
| -- Create folder if needed | |
| do shell script "mkdir -p " & quoted form of _output_posix | |
| repeat with _post in _posts | |
| set _title to _post's title | |
| set _published to _post's published date | |
| set _edited to _post's edited date | |
| set _status to _post's published status | |
| set _tags to _post's tags | |
| set _categories to _post's category names | |
| set _slug to _post's keywords | |
| set _excerpt to _post's excerpt entry | |
| set _body to _post's body | |
| set _permalink to _post's permalink | |
| set _postid to _post's post id | |
| if _published is missing value then | |
| set _date_prefix to my FormatDateYMD(_edited) | |
| else | |
| set _date_prefix to my FormatDateYMD(_published) | |
| end if | |
| set _safe_title to my MakeSafeFilename(_title) | |
| set _filename to _date_prefix & "-" & _safe_title & "-" & _postid & ".text" | |
| set _filepath to _output_posix & _filename | |
| set _text_file_contents to "Title:" & tab & _title & linefeed & ¬ | |
| "Blog:" & tab & (_blog's name) & linefeed & ¬ | |
| "Status:" & tab & _status & linefeed & ¬ | |
| "Originally Published:" & tab & _published & linefeed & ¬ | |
| "Edited:" & tab & _edited & linefeed & ¬ | |
| "Permalink:" & tab & _permalink & linefeed & ¬ | |
| "Tags:" & tab & _tags & linefeed & ¬ | |
| "Categories:" & tab & (_categories as string) & linefeed & ¬ | |
| "Slug:" & tab & _slug & linefeed & ¬ | |
| "Excerpt:" & tab & _excerpt & linefeed & ¬ | |
| "---" & linefeed & linefeed & ¬ | |
| _body | |
| set _fref to open for access POSIX file _filepath with write permission | |
| set eof _fref to 0 | |
| write _text_file_contents to _fref as «class utf8» | |
| close access _fref | |
| end repeat | |
| end tell | |
| on FormatDateYMD(_d) | |
| set _y to year of _d as string | |
| set _m to month of _d as integer | |
| set _day to day of _d as integer | |
| if _m < 10 then set _m to "0" & (_m as string) | |
| if _day < 10 then set _day to "0" & (_day as string) | |
| return _y & (_m as string) & (_day as string) | |
| end FormatDateYMD | |
| on MakeSafeFilename(_str) | |
| set _badChars to {":", "/", "\\", "?", "*", "\"", "<", ">", "|"} | |
| set _replacements to {"•", "-", "-", "-", "-", "-", "-", "-", "-"} | |
| set _result to _str | |
| repeat with i from 1 to count of _badChars | |
| set _oldTIDs to AppleScript's text item delimiters | |
| set AppleScript's text item delimiters to item i of _badChars | |
| set _parts to text items of _result | |
| set AppleScript's text item delimiters to item i of _replacements | |
| set _result to _parts as text | |
| set AppleScript's text item delimiters to _oldTIDs | |
| end repeat | |
| -- Truncate to 64 characters | |
| if length of _result > 64 then | |
| set _result to text 1 thru 64 of _result | |
| end if | |
| return _result | |
| end MakeSafeFilename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment