How to auto-run a simple script?
If the file is being run as a registered text block then

The text block's name must have a .py extension.

if __name__ == "__main__"


won't be true, it takes the module name, eg for test.py

print(__name__)


will print test, whereas when run from the text editor will print 

__main__  


which is handy for testing addon scripts.

For a registered text block, perhaps just having 

register()


without the if would suffice.