Applescript does not work in Debug, only Build

Hi, some of my applications use AppleScript. I use the last Xojo version under Sonoma.
When in DebugMode, some AppleScript don’t work but all work when the app is builded.
Is it because I don’t have Finder checked in my System preferences for Xojo?
If yes, how to add it?

You need to make an info.plist text file with content like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>NSAppleEventsUsageDescription</key>
  <string>Demo</string>
</dict>
</plist>

and drop that in the project, so you get a NSAppleEventsUsageDescription entry.

You may need also sign the debug build via a build-script, since Xojo here only uses ad-hoc certificates.

Thank you, I already modify the Plist with NSAppleEventsUsageDescription in Build and in Debug.
But I don’t sign the Debug (I don’t sign the Build neither as I don’t know how to do).

Signing is not necessary to test AppleScripts on your own machine.

Do you have a bundle ID set for your app? This is necessary for a lot of Apple functionality.

1 Like

I made small XojoSourceCode using my AppleScript (CopyReplacingNo).
CopiWithAppleScript
It works when the app is builded but in Debug it returns (in French):
Err n° -1743 : Non autorisé à envoyer des évènements Apple à Finder.
in English something like:
Err n° -1743 : Not authorized to send Apple events to Finder.
If you open the info.Plist of the Debug, the NSAppleEventsUsageDescription key is there.
I have a Mac ARM under Sonoma 14.5 (23F79) with Xojo 2024 r2.1 (both are uptodate).

I checked my project. I add the NSAppleEventsUsageDescription the same way you do, via Build-Script. In this case, at least on my Mac, i need to sign the debug build. Then it works.

But if i choose the way Christian described, via dropping a “info.plist” file into the project (no build script at all), then it works without signing the debug build. Not sure why. May i’m missing something.

Thank you very much for your test.

Edit: I must be dumb, here is what I have when I drop the Info.plist file in my project:

Edit2:
I edit the info.plist with BBEdit but it replace the 2 spaces by a Tab character before NSAppleEventsUsageDescription and Demo and that was causing the trouble.
I think Xojo may manage that.

Edit3:
No that wasn’t the Tab, I closed my project, reopen and re-add the info.plist (with Tab before NSAppleEventsUsageDescription and Demo and it works. Sorry, I don’t understand :dizzy_face: :thinking:

Try to modify the plist with XCode…

Or PlistEdit Pro, which is awesome.

If I drop a Info.plist containing the key NSAppleEventsUsageDescription and I modify the Info.plist with my XojoBuildScript (just to add the DateBuild, not to add the NSAppleEventsUsageDescription key) then I can’t copy with the AppleScript.
→ Modify the Info.plist with a Xojo script prevent the use of AppleScript.
I think I will fill a bug report.

Does it work if you just use the info.plist without modifying it?

Yes it works if I don’t modify the info.plist with XojoScript.

I have created an issue #77167.

2 Likes

Hi @Thomas_ROBISSON

Please, try adding this line of code at the end of your XojoScript:

Var Signing As String = DoShellCommand("codesign --force --deep -s - " + TpTextA)

1 Like

Thank you very much Javier, it works. I have a message “PathToMyApp**: replacing existing signature**” when I run the Debug another time but it works too, I suppose it’s normal.

I added

If DebugBuild Then Var Signing As String = DoShellCommand("codesign --force --deep -s - " + TpTextA)

As it is not necessary to do that when I build application as it works when I build application. Or should I execute this line even when I build app?