Two options:
If the app has an Applescript API, you can use that directly. Find out by opening Script Editor, and then drag-and-dropping the application onto Script Editor's icon in the Dock.
If not, Applescript GUI scripting may be able to do what you want.