As to the script, it would be fairly simple:
1) Check the latest job state.
2) If it is equal to running, wait a pre-defined interval and, then, proceed to step 1. Otherwise, proceed to job execution.
If you need any assistance with scripting, kindly, create a topic in the corresponding subforum.