- Set the title of the window to the name of the script that is creating it. This helps in the debug process when you find one (or many) offscreen windows left open by scripts; moreover it makes very easy to close the right window at the end of the script (by specifying the script name as the title of the window for the close command), this greatly reduces the risk of conflicts in the window usage because every script, also if it is called as a subscript, will always open and close its personalized window. The only case in which this method needs additional precautions is the event of recursive script calls, in this case the script should be able to reuse an open window (for resource usage efficiency) or open a specific window for every running instance of the script (for example by appending a random number at the end of the window title to uniquely identify it).
- I created a script called "Create offscreen window ( title )" which I call in my scripts when I need a working window for them. In this script I create an offscreen window with the specified title; if the current user is a developer the window is not placed offscreen for debug purposes. This script gives me a cleaner perception of the solution because I have this explicative script called instead of hundreds of Create new window commands around in my scripts. As far as you avoid or manage recursive calls, this script can be modified to recycle existing windows when the specified title matches an existing window's title.
These are practices that I'm constantly using but they are far from refined; for instance I was thinking about a custom function to generate a unique script instance identifier (something like script name & timestamp & random number) that could be useful for debug/log purposes (with recursive script calls too) and also usable as a title for their working windows, but at the moment the techniques I described above are enough for me.