PSA: don't do your first AppleScript in a thread

With the latest update to XProtect at the beginning of December Apple (silently!!!) now requires any AppleScript done with NSAppleScript to be initialized on the main thread. Otherwise the app hangs! Subsequent AppleScripts can be run in a thread.

See XProtect makes app hang when runni… | Apple Developer Forums for the discussion in the Apple developer forum.

4 Likes

Good grief what a mess.

XProtect should do all that initialization automatically if the app claims the AppleScript entitlement.

Yup. I do not know what these people are thinking anymore. Really, it’s only security theater. And it took me only a couple of minutes to work out that both non-threaded NSAppleScript and osascript do work.

I suppose osascript works because it’s a separate, presumably non-threaded process.

For me it looks usually more like the old senior developers retired and the new developers don’t yet know all the reasons why you do something a certain way. Like that dispatch_sync to main thread may be bad in a multi threaded app.

Now we have to run a small AppleScript doing nothing in main thread on startup as a workaround.

3 Likes

I ran into this issue and, interestingly, changing the thread to preemptive allowed the script to run.