Applescript silent failure when run from Script Menu in Menu Bar

Recently I purchased a new M2 mac running OS Ventura. I have just tried to run an Applecript that has OmniGraffle draw a year planner and populate it with events from a selected calendar. When I attempt to run the script from the menu bar I see a gear wheel appear for a few seconds then nothing. Nothing happens in OmniGraffle and no error messages are posted. If however I run the same script from inside Script Debugger v8 the script runs as expected. I suspect that some component that the script calls may not be in the correct folder but I thought I would ask for help before blundering about inside the library folders.
My script uses the following :

use AppleScript version “2.4” – Yosemite (10.10) or later
use framework “Foundation”
use scripting additions
use script “Dialog Toolkit Plus” version “1.1.0”
use script “CalendarLib EC” version “1.1.5” – put this at the top of your scripts

NOTE: Dialog Toolkit Plus.scptd should be in ~/Library/Script Libraries

Is it possible that ScriptDebugger seeks additions in more locations than the menu does?

I apologise for the odd formatting of my previous post…

Two thoughts:

  • You can wrap the entire script in a try block to display the error:
try
	# Your script here.
on error m number n
	display dialog m & "\n\n" & "(" & (n as string) & ")" with icon stop buttons "Exit" default button 1
end try
  • Some of the script libraries look like they would use the AppKit framework. You’re only importing Foundation. Script Debugger may load the required ASObjC bridging files, but the default script menu calls osascript, which will not.
    Try adding:
use framework "AppKit"

Each AppleScript runtime programs have security limitations. They are different from each other.
Script Debugger and Script Menu have some different limitations.

If you want to run your script at same as Script Debugger, you’d better to export it as “Extended Applet”.
Then put the applet into the Script Menu. It will run same as Script Debugger.

Tree_Frog, thanks for the suggestions; unfortunately neither have solved the issue. The problem appears to be with access to the Calendar data via CalendarLib EC. Adding the Try statement caused the following to be posted :

EKEventStore doesn’t understand the “alloc” message.

What is odd is that on two occasions the script has run correctly from the script menu but I cannot discover why.

Piyomaru Do you mean ‘Enhanced Applet’ ? If yes, I tried saving in all the app forms with no positive result. When running any of the applets a security warning is posted followed by an error message to the effect that the code is unable to located the “Security & Privacy” pane. This occurs even if the “Privacy & Security” pan is open (note the error in the name). All this occurs despite the applet having been granted permission to access calendar data.

I surmise that the script runs from inside Script Debugger because it has been granted permission to access calendar data. The two occasions where the script has run are probably down to errors in the security protocols after all Apple seem unable to decide on the correct name of the pane.

For the record I’m using Ventura 13.5.2 - bring back Snow Leopard!

Thanks for all your suggestions,
best wishes
Simon

You can try the following:

  • Add the following to the AppleScript:
use framework "EventKit"
  • Manually add the following to the Calendar pane in Privacy & Security System Settings:
/usr/bin/osascript

I’d also highly recommend looking at FastScripts 3 as an alternative to the stock Script Menu – it avoids a lot of these issues by having its own bundle id & by keeping ASObjC terminology loaded between script runs (along with many other features!).

Adding

use framework “EventKit”

appears to have solved the issue although some errors are getting thrown referencing bad calendar objects. So many thanks for the advice.

I can see no method of manually adding anything to the Calendar pane of Privacy & Security Settings and reading other posts it seems that Ventura has issues with allowing scripts to open the Security & Privacy panes. Running my script seems to confirm this as despite the System Settings being opened by the scrip “something” throws or issues a user cancelled dialog and the Security Pane is not displayed: unfortunately its difficult to say what is throwing the error as error messages are posted on top of each other but all clear together. Thank you Apple!

My limited understanding, based on wrestling with it when creating a “widget” for Livecode that reads Calendar Events, is that an application may only be added to the list by it calling the required Objective-C / Swift routine which both adds the application to the list and also prompts the user for permission. No matter how the user answers the application is listed with the users response indicated by the status of a checkbox or slide switch in the UI depending on the recent version of the UI. The really brave can edit the SQL table, at least you could when running under Big Sur.

I suppose all this security is a good thing but only if Apple test it thoroughly and fix it if and when broken.

I have tried FastScripts and it allowed the Applescript to run before the addition of the line posted above. So thanks again; I think I will be using it in the future.

best wishes
Simon

1 Like