Applescript: setting the desktop background folder


I keep several folders of desktop background images, and cycle through their contents randomly. I'd like to be able to set the active folder without having to open the Preferences window and do it manually with the "Choose Folder" option. I know how to set a particular file as the desktop background using Applescript, but I can't work out how to go about setting the active folder for a random cycle. Recording an Applescript doesn't seem to work either.

Any ideas?

Thanks :)