Like many users of Time Machine, I have a need to back up to different disks at different times. For instance, when my laptop is at home I want to back it up to an external drive for data security, but when I am on the road, I'd like to have it back up to a partition on the internal drive so I can use it as a way to "undo" file changes and quickly access deleted files.
This normally requires manually setting the Time Machine preferences every time you want to switch drives. So I put together an AppleScript to do this, and launch it automatically when my external drive is mounted or unmounted (using the free utility Do Something When).
The script uses GUI Scripting to set Time Machine to backup to a "primary drive" (the primarydrivename variable in the script) if it is available, and if it isn't, it will attempt to have it backup to a "secondary drive" (secondarydrivename). Failing that, it leaves the Time Machine preferences unchanged.
[robg adds: I haven't tested this one.]
Mac OS X Hints