That will teach me to try everything possible before I post. Opened two different applications, started working with both, triggered the script (now an application) and it prompted me to save both documents before quitting the applications.
john202307. I primarily use a handler (which I happen to name “main”) in this circumstance to prevent top-level variables from being saved with scripts on computers running older versions of macOS. This is seldom an issue any more, and I won’t do that in the future. To fix whatever issue this handler is causing (although I can’t imagine what that would be), just delete all of the following lines: