On 22 Aug 2015, at 11:31 am, Stockly, Ed <email@hidden> wrote:
That worked, but now I'm getting this error from the script:
display alert "This script must be run from the main thread." buttons {"Cancel"} as critical
Long answer:
Modern applications are multi-threaded, but there are certain things that all applications must do on the main thread, or as Script Editor calls it, in the foreground. These are mainly anything to do with the interface. So when the script wants to show an alert or date picker via ASObjC, it needs to be running on the main thread.
When you run an applet, or you run a script from a script menu or panel, it gets run on the main thread. It used to be that when you ran a script in a script editor, it would be run on the main thread. But these days editors run scripts on background threads, to free up the main thread for their own purposes -- it helps make it possible to have multiple scripts running, and so on. Until ASObjC came along, this was never really an issue.
So the issue is only in editors, when you're writing and testing scripts. Fortunately, Script Editor retained the ability to run a script on the main thread, albeit not in an obvious way. Unfortunately there's no way to do it from Script Debugger. (And there's a checkbox for it in ASObjC Explorer.)
This is another good reason to factor your scripts using script libraries. Breaking out the foreground stuff can make developing a bit easier.
All the non-UI stuff, like using data detectors, manipulating strings, lists, dates and so on, can be run pretty much any old how.
|