Still learning scripting I've noticed that my scripts run fine, but if I accidentally click on another document whilst the script is running then this will throw the script out and it'll pop up an error. What is the best way around this - the obvious thing would be to isolate the script from any user interference but that may have propblems if it when into a loop. Any suggestions?
Actually, depending on the version of PS and what platform you're on (and platform specific focus policy) it can be pretty easy to change the 'active' document via the UI inadvertently while a script is running. It has caused me all kinds of grief over the years with scripts like CSX. As a result, I add code to repeatedly make sure that the active document is the one that I expect it to be. And CS5 introduced yet another problem for CSX that took a few days to work around.
The safest thing to do is move the mouse cursor away from PS while your script is processing if you are seeing the active doc change unexpectedly.