I like RapidWeaver and really like the idea of static pages for my website (it’s not as if I update it that often !) but I also have one or two posts in WordPress that I don’t want to loose. Currently, there is no AppleScript or Automator support in RW and the plugin dev kit is not yet out[1] (it’s promised for v3.5, but the current application release is v3.5 Public Beta 1) so I thought I’d try a little GUI Scripting.
Hooboy. It’s harder than AppleScript, but then I find AppleScript hard anyway as I’m a person who never managed to complete an Infocom text adventure. Yes, of course it’s plain English, but after trying the fifteenth variant of get (pickup, take, hold, grab, steal, nick…) and still getting “I don’t understand” I just went off to do something easier and more obvious. Like 6502 assembler and Forth.
AppleScript is like that: maybe if I spoke a more US variant of English it’d be easier, but GUI Scripting takes it to a new level as it’s necessary to switch from ‘plain’ English to a more computer-oriented variant as there is no easy way to describe UI elements without using the names that have been given to them. Take the following, for example:
tell application "Finder"
activate
end tell
tell application "System Events"
tell process "RapidWeaver"
activate
set projectName to "test.rw3"
set postTitle to "This is my post title"
set postCategory to "Photography"
set postBody to "This is my post body (ie: the content)"
set postDate to "1970/01/02 11:22:33 +0000"
set postPermalink to "this-is-my-post-title"
delay 4
click button 1 of splitter group 1 of group 1 of splitter group 1 of splitter group 1
of window projectName
set tf to text field 2 of splitter group 1 of group 1 of splitter group 1 of
splitter group 1 of window projectName
set value of tf to postTitle
set tf to text area 1 of scroll area 1 of tab group 1 of splitter group 1 of group 1
of splitter group 1 of splitter group 1 of window projectName
set value of tf to postBody
click checkbox "Custom Permalink" of tab group 1 of splitter group 1 of group 1
of splitter group 1 of splitter group 1 of window projectName
set tf to text field 1 of tab group 1 of splitter group 1 of group 1 of
splitter group 1 of splitter group 1 of window projectName
set value of tf to postPermalink
set pb to pop up button 1 of splitter group 1 of group 1 of splitter group 1
of splitter group 1 of window projectName
tell pb
click
keystroke down
end tell
set df to UI element 1 of splitter group 1 of group 1 of splitter group 1
of splitter group 1 of window projectName
set value of df to postDate
end tell
end tell
That ought to be enough to create a new blog entry, fill in the title, custom permalink, body, category and date. What it does do is create a new item, set the custom permalink flag, occasionally fill in the custom permalink text itself, and throw the date into the search field. This is even with the help of the 30 day trial of UI Browser – in fact, without that trial I don’t think I’d even have got this far.
The result ? Well, I think I’m going to give up on this totally unless anyone else has some better tips for getting this sort of thing automated and wait for the dev kit and write a plugin to grab the posts directly from the WordPress database and leave it running as a non-public backend (or possibly translate the posts into a format that the normal blog plugin can use: it depends on how much sample code comes with the dev. kit).
[1] Ahem. The SDK is now out