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.
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.
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
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.
... 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.