Only executing when application has become main

Ok so I am writing an application which runs a terminal script to re-encode video (uses mpeg2enc)
I have a NSTableView element working as a batch encode list.
I have it set up so once the terminal is done encoding and muxing it runs an osascript call to activate the main application GUI again.

What I need to figure out how to do… is make the script only execute the first encode and wait until the application gets activated again to go on to the next in the list. Or I can make the application wait until finder sees a file name of the same as the encoding file but as a .mpg. Muxing of the mpg is the last step so there should be little overlap then but no big deal.

I was thinking if anyone knew an easy way to do something like this. I’ve seen the ‘became main’ part but I don’t think I could use that.

Anyone want to point me in the right direction?

Moving to AppleScript Studio forum.