I actually put in another statement in the last block of code, clearing the keyboard buffer I believe, so now the script runs transparently in the workflow, as if it were never executed when it is done.
Here is the block calling system events to restore it all
Code:
tell application "System Events" to tell application process frontapp
key down control
key code 118
key up control
key code 36
end tell