This is probably a good place to start: MacScripter