I frequently record Keynote presentations I give using my Mac (using ProfCast). Typically I use a wireless lapel mic and have my sound preferences pane set to record from Line In. However, on occasion I forget to turn on my mic, or the battery is dead, and so I get nothing but silence. In these instances, I'd like to be able to use my PowerBook's internal mic as a backup, so I set about finding a method using AppleScript to accomplish this.
I eventually got something working with the help of a freeware program called AudioLeak that monitors the RMS sound level of the selected input source. Together with a little GUI scripting, I can have my Mac try to connect to Line In, but switch to the internal mic if the line is dead. Here's the final script.
I have this script embedded in a droplet, so that I drag a Keynote file onto the droplet and it runs this script along with some other stuff I want to do just before starting a presentation (i.e. check monitor resolution, hide all other apps, etc), and then launch the file in Keynote. Alternatively, you could have this script run periodically using iCal or cron or an idle handler.
In addition to AudioLeak, you'll need to have GUI scripting enabled (in System Preferences » Universal Access).
[robg adds: I haven't tested this one.]
Mac OS X Hints
http://hints.macworld.com/article.php?story=20070624210918356