AppleScript app sometimes just stops (gets stopped?)

The AppleScript app I maintain just stops at some point, however what point varies. I suspect it gets stopped for some reason, but I can’t figure out why…

From my own log-statements in AppleScript, I suspect it stops while waiting for the results of a child process. It’s a call to psql, which queries or updates our postgres database. Something like:

set cmd_result to do shell script "export PGCONNECT_TIMEOUT=5; " & ¬
    "/path/to/psql --no-psqlrc postgresql://localhost:5432 " & ¬
    "-f /path/to/sql/file.sql"

The psql command is bundled with the app, and is a Universal build for both Intel as Apple silicon. The app itself is signed, notarized & stapled with SD Notary. I also use the Dialog Toolkit Plus for dialogs.

Because of logging, I know the command has started. And because the database hasn’t been altered (and also the logging after this command hasn’t ran), I guess the process gets stopped somehow. The app just stops (dot under app icon in dock disappears) and there is no error message.

And sometimes the app just runs fine, even running all the pqsl commands. At the start of the script, there are psql commands for reading data. I know in the beginning the script also gets stopped, but I haven’t been able to narrow this down. However, at the end, there are two psql commands: I’ve seen multiple times the app gets stopped at the 1st, but also at the 2nd psql command…

I haven’t been able to reproduce it reliably. It happens both on Ventura and Sonoma (I haven’t got other installations at the moment). I’ve also ran Console.app along the crash, and the following entries got my attention, but I haven’t got a clue as what they mean:

applet:
__delegate_identifier__:Performance Diagnostics__:::____message__:This method should not be called on the main thread as it may lead to UI unresponsiveness.
__delegate_identifier__:Performance Diagnostics__:::____message__:Synchronous URL loading of <private> should not occur on this application's main thread as it may lead to UI unresponsiveness. Please switch to an asynchronous networking API such as URLSession.

tccd:
TCCDProcess: identifier=nl.archipunt.zaak-script, pid=19680, auid=502, euid=502, binary_path=/Applications/Script voor Zaken.app/Contents/MacOS/applet attempted to call TCCAccessRequest for kTCCServiceAccessibility without the recommended com.apple.private.tcc.manager.check-by-audit-token entitlement
Prompting policy for hardened runtime; service: kTCCServiceAddressBook requires entitlement com.apple.security.personal-information.addressbook but it is missing for accessing={TCCDProcess: identifier=nl.archipunt.zaak-script, pid=19680, auid=502, euid=502, binary_path=/Applications/Script voor Zaken.app/Contents/MacOS/applet}, requesting={TCCDProcess: identifier=com.apple.mds, pid=339, auid=0, euid=0, binary_path=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Support/mds},
Prompting policy for hardened runtime; service: kTCCServiceCalendar requires entitlement com.apple.security.personal-information.calendars but it is missing for accessing={TCCDProcess: identifier=nl.archipunt.zaak-script, pid=19680, auid=502, euid=502, binary_path=/Applications/Script voor Zaken.app/Contents/MacOS/applet}, requesting={TCCDProcess: identifier=com.apple.mds, pid=339, auid=0, euid=0, binary_path=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Support/mds},

runningboardd:
RBSStateCapture remove item called for untracked item 389-324-72111 (target:[app<application.nl.archipunt.zaak-script.6556885.6556894(502)>:19680])

About the Performance Diagnostics__: I suspect they have to do with the Dialog Toolkit Plus, but they don’t seem to be the reason my app is quit.

About the tccd messages:

  • I don’t know why I would need the com.apple.private.tcc.manager.check-by-audit-token entitlement.
  • Same for com.apple.security.personal-information.addressbook.: as far as I know I don’t use the Contacts.app
  • Same for com.apple.security.personal-information.calendars.

Anyways, I’m a bit stuck here. What information am I missing here.

Why could my app be stopped by presumably MacOS? Where can I look for more info. What do I look for in Console.app. Any answer would be appreciated.

What happens if you give the app those rights when notarizing?

Thanks for helping. When I check the addressbook and callendars checkboxes, those tccd messages don’t appear in the log anymore, but the app still get’s stopped sometimes; still same behaviour as far as I can tell.

When I also “check” the com.apple.private.tcc.manager.check-by-audit-token entitlement via the Extra entitlements… checkbox, the app get’s killed by Finder, with the following message:


That could have been expected, because it’s a private entitlement.

From another mention of this entitlement I got the idea to check the released notarized version for entitlements:

$ codesign -d --entitlements :- path/to/the.app | plutil -p -
Executable= path/to/the.app/Contents/MacOS/applet
Warning: Specifying ':' in the path is deprecated and will not work in a future release
{
  "com.apple.security.automation.apple-events" => 1
  "com.apple.security.cs.disable-library-validation" => 1
}

So I added those two entitlements also to the custom entitlement plist file (with the check-by-audit-token removed). However, to no avail. The app still quits sometimes…

I also used Howard Oakley’s Mint utility, which extracts logging easier. With the TCC-button, I got the following logs. I see LaunchServ reporting about stopping my app, but I don’t see any information as to why.

24-03-28 11:22:13.198 LaunchServ  ADDING: App:"Script voor Zaken" asn:0x0-531531 pid:69616 refs=7 @ 0x1313255a0 exitStatus=0
24-03-28 11:22:13.198 LaunchServ  CLIENT: 0x130605ce0/409 Need to lookup or create kLSDefaultSessionID for client.
24-03-28 11:22:13.198 LaunchServ  ADDING { "ApplicationType"="Foreground", , "CFBundleExecutablePath"="/Applications/Script voor Zaken.app/Contents/MacOS/applet", , "CFBundleIdentifier"="nl.archipunt.zaak-script", , "CFBundleShortVersionString"="1.9.9", , "CFBundleVersion"="1.9.9dev", , "DeathTime"=now-ish 2024/03/28 11:22:13, , "LSBundlePath"="/Applications/Script voor Zaken.app", , "LSDisplayName"="Script voor Zaken", , "LSExitStatus"=0, , "pid"=69616 } to sDeadApplicationInformation for 69616
24-03-28 11:22:13.198 LaunchServ  CLIENT: 0x131306320/713 Mapped requested session to session id 100030
24-03-28 11:22:13.205 LaunchServ  Sending reconnection to conn (Connection) <connection: 0x1314063d0> { name = (anonymous), listener = false, pid = 0, euid = 0, egid = 0, asid = 0 }
24-03-28 11:22:13.205 LaunchServ  DEATH: Removing app App:"Script voor Zaken" asn:0x0-531531 pid:69616 refs=6 @ 0x1313255a0 from sRunningBoardDeathNotificationsSetRef.
24-03-28 11:22:13.205 LaunchServ  Sending exit status and unregister application, app=App:"Script voor Zaken" asn:0x0-531531 pid:69616 refs=5 @ 0x1313255a0, exitStatus=0

Any other ideas?

You could try giving the applet Developer Tools access under Privacy & Security. Otherwise I suspect you’re out of luck.

If you believe that you app is being stopped unjustly due to unnecessary or ambiguous security restrictions, you can submit a bug to Apple with a detailed description of what happens and why you believe it’s wrong. Apple sometimes actually replies to some feedback submitted under niche categories such as Developer Tools, Notarization etc. They may even suggest how to address the issue, when applicable.

1 Like

If you are a member of the Apple Developer Program you can request two “Technical Support Incidents” a year. TSIs give you:

"… code-level support for Apple frameworks, APIs, and tools from an Apple Developer Technical Support Engineer. "

You can request a TSI after logging into your Developer account.

More info:

Cheers.

1 Like