This would require use of Applescript, which is something I have no idea how to use
I suggest asking this same question on
www.macrumors.com (NOTE: I only redirect here when I dont know how to answer) and asking the people there. There is bound to be someone there who knows how to use Applescript.