Error: Event: AdobeScriptAutomation Scripts may modify the state of Photoshop. Such events are only allowed from inside a modal scope
I am still navigating and learning scripting. my understanding from this error is that you need to use ExecuteAsModal for anything that change Photoshop state.