<p>From the Displays pane in System Preferences, I can manually change the main monitor by dragging the menu bar from one display to the other. I'd like to automate this and make it part of an AppleScript.</p>

Much like you can tell System Events.app to sleep your Mac, you can tell Image Events.app to mess with your displays.  The Image Events application provides a "displays" collection.  Each display has a "profile" with lots of goodies.  However, everything I just mentioned is read-only, so I don't have a good way to do it from within script.
You might have better luck in Automator – Hit record, run System Preferences, go to Displays, drag the menu bar to the other screen, and hit stop.  I bet something will work.