Check whether there is a mainwindow or an image
Now it's possible to run scripts, there isn't necessarily a mainwindow once there's a document.