AppleScript

http://mactoids.com/learn-applescript-and-automate-your-mac/