iPhoto said it had to rebuild its database, and afterwards the previous manual sorting of events was all messed up.
I tried restoring an older database from backup but iPhoto would just rebuild again, messing it up again.
I was able to extract the original order of events from the AlbumData.xml
file inside a backup of the iPhoto library (editing this file won't fix the order, sadly).
I can't find a way to change the manual event order with AppleScript or anything else (maybe you could do it with SQLite somehow).
But it seems more feasible to edit iPhoto event titles, adding number prefixes ("1. My first event", "2. My second event") and then sort events by title instead of manually. This also seems less fragile going forward. New events could be named "1.1 My middling event" to go inbetween.
But to achieve this, it would be convenient if I could batch-edit the titles programmatically. Is that possible? I don't see anything useful in the AppleScript Dictionary.
I started numbering them manually, then I realized iPhoto has pretty scriptable keyboard shortcuts: when editing one event title you can tab to the next one. So I scripted that.
This is a pretty ugly and hackish mix of Ruby (my weapon of choice) and AppleScript, and it's written to solve my specific problem, but it probably gives a good idea of how you can do this:
Also available as a Gist.