Script for batch tasks

I've been trying to create a script to run batch tasks by emulating the keyboard shortcuts, but I'm getting nowhere. Can anyone point me in the right direction (whichever direction that is)? E.g. I'd like to run Analyse Files, auto-select 'Finish', then 'Close', then 'Yes' (to reopen the file) and then go to first untranslated segment. Maybe trying to reinvent a wheel here?

Thanks,

Olly