Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Applescript syntax for editing published post

edited August 2012 in MarsEdit
What is the proper syntax for editing an existing post? It seems as though I can only apply edits to "documents" (open windows?), but cannot turn a post into an editable document.


  • Hi Nik - Hmm, this may be a hole in the AppleScript support. I thought that e.g. "open post 1 of blog 1" would create a new document, but that doesn't seem to be working in my tests.

    What is the specific type of scripting flow you are hoping to achieve? Maybe we can come up with an alternative for achieving it.
  • Yeah, opening isn't doing the job.

    What I'm working on is I switched a domain, so I have a ton of links in my blog posts that need redirecting. I wanted to find those posts with the bad links (easy to do) and then replace the bad links with replacement ones. Pretty straightforward.

    I may just have to use UI scripting and keep clicking down, open, etc. Not elegant and a bit failure prone, but it'll probably do the job.
  • Here's the script that ended up working for me. Had to go back and fix a few manually where things got slow or it just skipped for some reason, but it got the job done.

    tell application "MarsEdit"
    repeat 100 times -- or whatever
    tell application "System Events"
    keystroke return
    my unLinkDoc({"", "", ""}, "")
    delay 3
    keystroke (ASCII character 31)
    delay 1
    end tell
    end repeat
    end tell

    on unLinkDoc(oldurls, newurl)
    tell application "MarsEdit"
    tell document 1
    set pubdate to published date
    set b to body as text
    set oldTIDs to (AppleScript's text item delimiters)
    set AppleScript's text item delimiters to oldurls
    set btis to text items of b
    set AppleScript's text item delimiters to newurl
    set nb to btis as text
    set AppleScript's text item delimiters to oldTIDs
    set body to nb
    set published date to pubdate
    send post to blog
    end tell
    end tell
    end unLinkDoc
  • Accepted Answer
    Glad to hear that you got the job done. Yeah, using UI Scripting is definitely less than ideal. I'll have to try to get the expected open behavior working in MarsEdit.
  • Daniel, is there any news on this? Is UI scripting the only angle for programmatically modifying a pre-existing post via Applescript?
  • ... it seems pretty tricky to modify a post, even using UI scripting. For example, since "selected post" and "selected blog" are read-only properties, how would I go after a desired post? The only way I can see is to script the keystrokes to start at the top and arrow down, testing "selected post" until the desired one is highlighted, and then opening the document via "return" as Nik did.

    Alternately, do you happen to have any recipes for updating a WordPress post directly using one of the APIs, i.e. via curl (or anything close)? :-)

    Loving MarsEdit so far, and hoping I can pull off this scripting too.
  • Hi j0hn - yeah unfortunately for the time being I think the UI access based scripting is the best bet. I don't have any ideas about scripting it via curl. The WordPress API is complicated enough that it would be fairly complicated to send a post, let alone make minor edits to an existing one.
  • OK, thanks Daniel. Cheers, have a great weekend.
Sign In or Register to comment.