It's cheating but what happens if you run the script as an argument to the terminal app and exit at the end?