App hangs when running AppleScript

Got a hang from a user where my app hangs on running the first AppleScript the app does:

Thread 0xd3391 28 samples (1-28) priority 31 (base 31) last ran 162.982s ago
<thread QoS default (requested default), process unclamped, jetsam priority 100 (requested 100, assertion 0), process memory limit 0MB, process received importance donation from WindowServer [168], process received importance donation from distnoted [440], IO tier 0>
28 thread_start + 8 (libsystem_pthread.dylib + 7080) [0x18bfa4ba8] 1-28
28 _pthread_start + 136 (libsystem_pthread.dylib + 27656) [0x18bfa9c08] 1-28
28 ??? (XojoFramework + 1309844) [0x105acfc94] 1-28
28 ??? (XojoFramework + 2624740) [0x105c10ce4] 1-28
28 Delegate.IM_Invoke%%o + 60 (Mail Archiver X + 19043840) [0x101c7d600] 1-28
28 CCEmailView.CCEmailView.TGetMailboxes_Run%%o<CCEmailView.CCEmailView>o + 8436 (Mail Archiver X + 22318064) [0x101f9cbf0] 1-28
28 GetImapStatus.Constructor%%os + 2392 (Mail Archiver X + 29929112) [0x1026dee98] 1-28
28 GetImapStatusMail.getAccounts%A1s%o + 220 (Mail Archiver X + 29911788) [0x1026daaec] 1-28
28 GetImapStatusMail.getAllAccounts%A1s%o + 732 (Mail Archiver X + 29913736) [0x1026db288] 1-28
28 RunAS.Constructor%%oA1sA1i8bbb + 2980 (Mail Archiver X + 16358172) [0x1019edb1c] 1-28
28 RunAS.compileScript%b%o + 948 (Mail Archiver X + 16380980) [0x1019f3434] 1-28
28 NSAppleScriptMBS.compile%b%o&o + 72 (Mail Archiver X + 12116784) [0x1015e2330] 1-28
28 compileAndReturnError(REALobjectStruct*, _REALdictionary*&) + 112 (MBS_MacCocoa_NSAppleScript_Plugin_21300.dylib + 27628) [0x114a7abec] 1-28
28 -[NSAppleScript compileAndReturnError:] + 136 (Foundation + 9808488) [0x18e195a68] 1-28
28 OSACompile + 52 (OpenScripting + 78068) [0x1ad4bb0f4] 1-28
28 SecurityPolicyTestDescriptor + 152 (OpenScripting + 8836) [0x1ad4aa284] 1-28
28 _SecurityPolicyTest(char const*, void const*, unsigned long) + 332 (OpenScripting + 8472) [0x1ad4aa118] 1-28
28 InterpreterSecurity_ScanBuffer + 112 (libInterpreterSecurity.dylib + 4868) [0x286351304] 1-28
28 -[InterpreterSecurity scanData:withSourceURL:] + 164 (libInterpreterSecurity.dylib + 3508) [0x286350db4] 1-28
28 -[XProtectScan beginAnalysisWithFeedback:] + 544 (XprotectFramework + 40536) [0x1cd7a9e58] 1-28
28 -[XPMalwareEvaluation initWithData:assessmentClass:] + 92 (XprotectFramework + 11684) [0x1cd7a2da4] 1-28
28 -[XPMalwareEvaluation initWithRuleString:withExtraRules:withURL:withData:withAssessmentClass:feedback:] + 36 (XprotectFramework + 12968) [0x1cd7a32a8] 1-28
28 -[XPMalwareEvaluation initWithRuleString:withExtraRules:withURL:withData:forcedRulesOnly:withAssessmentClass:feedback:] + 992 (XprotectFramework + 13972) [0x1cd7a3694] 1-28
28 _dispatch_sync_f_slow + 148 (libdispatch.dylib + 71640) [0x18bdfc7d8] 1-28
28 DISPATCH_WAIT_FOR_QUEUE + 368 (libdispatch.dylib + 72736) [0x18bdfcc20] 1-28
28 _dispatch_thread_event_wait_slow + 56 (libdispatch.dylib + 15116) [0x18bdeeb0c] 1-28
28 __ulock_wait + 8 (libsystem_kernel.dylib + 10980) [0x18bf68ae4] 1-28
*28 ??? (kernel.release.t6000 + 6509224) [0xfffffe0008e852a8] 1-28\

The user is on the RC of Tahoe 26.2. I do not see the same issue on my computer with the same version of macOS.

The user already restarted his computer, reset the privacy permissions for my app and tried another app which does AppleScript for Mail.

Does anyone have an idea what the user could try to do?

I’m not sure I’ll be able to read / help with this one, but when posting logs please post the text file or use the code format. Quote format eats the asterisks and spacing because Markdown.

There’s going to be so many moving parts here that we probably won’t be able to help unless you can break it down into smaller pieces.

The first thing I would try is to have the user run the AppleScript from Script Editor and see what happens.

1 Like

The AppleScript works fine when run from the ScriptEditor.

The user also has tried SafeMode which didn’t work and another user which did work.

Hi Beatrix.

Did you ever solve this?

We are now getting the same problem with one of our apps that uses AppleScript via MBS and I have noticed the stack trace is similar to yours.

The bug should be fixed with the latest release of XProtect. However, I kept some workarounds by switching a few of my scripts to osascript when in a thread. It’s not like I trust Apple.

The Mac is on 26.2 so it looks like it hasn’t been fixed.

We are also calling the scripts from a thread so I might have to investigate the osascript route like you.

Thanks.

The rollout of XProtect is not immediate. Check the Eclectilight blog on how to get the XProtect version.

Using osascript instead of MBS is not that complicated. I had some old badly quoted stuff which I modernised. It’s possible to use Foundation framework in osascript which I used to make json out of arrays.

I’ve just checked the XProtect version and it is the latest.

I will update our code to avoid the issue.

Thanks.

Try running a script on the main thread before running any other scripts run in a thread.

Just choose something fast that doesn’t actually affect anything in the app that you’re calling.

After that script runs successfully, your threaded scripts should run fine from there on out.

Hi Jared.

Thanks for your suggestion.

I actually fixed it by subclassing AppleScriptMBS and overriding the compile method so that the compilation occurred on the main thread via CallMethodOnMainThreadMBS. My scripts are only a few lines long so no noticeable UI blocking occurs during the compilation.

1 Like

That’s a really clean solution.

I’ll have to look into that myself.

Thanks!