I google this error, it happens to me when I do things in main thread with AppleScript. Some say its not a error its compile error. Other say it happen when execution try to access memory it doesn’t have access to.
To be clear, the code I use do work… it only happen sometimes.
This is likely caused by invalid object references or bad pointers. Which is either due to a bug in the program you’re scripting or because you’re calling non-Applescript functions, e.g. via the ObjC bridge. Are you doing that?
@tempel
It happens sometimes when I do AppleScript on main thread. I use AppleScriptObjC code
and I use AppKit and other frameworks. If I run the same code again it works without error.
In other words it happens sometimes and for the most times it works.
The code is running from Script Editor, do you suggest I will run it somewhere else?
Yes, that’s what I meant - if you pass object refs that are not valid, you’d run into this type of crash. For example, if you keep using an object that has already been freed.
And why do you mention “main thread”? Are you also running AppleScript code in other (background) threads? That might be instable in itself, but I’m not sure.
When I use AppKit I need to run it on main thread.
I have used same approach on Mojave without any issues. It start on Monterey.
I always start with this, and it has work very well.
use framework "AppKit"
property arguments : missing value
on run
try
if my NSThread's isMainThread() as boolean then
my performDialog:arguments
else
my performSelectorOnMainThread:"performDialog:" withObject:"arguments" waitUntilDone:true
end if
on error the errorMessage number the errorNumber
set the ErrorText to "Error: " & the errorNumber & ". " & the errorMessage
return the ErrorText
end try
end run
on performDialog:arguments
-- Some code
end performDialog: