JXA Library functions on Catalina make script editor crash every time

Hi,

Is there any information about a deprecated support of JXA script libraries in Catalina ?

I have a JXA Script Library I use for some tasks automation in Numbers and Pages and since upgrading to Catalina it doesn’t work any more
The lib file is in “~/Library/Script Libraries” and the calling function are like

var j = Library(“jxalibtotest”)
var path = Path(‘/Users/xxxx/Library/Script Libraries/jxalibtotest.scpt’);
var finderApp = Application(“Finder”);
var status = finderApp.exists(path);
console.log("File exists " + status). // File exists OK !

var test = j.isLoaded()
//
// isLoaded() is a func of the library and it’s crashing every time here
// the same code worked well in Mojave

Thanks for any help or comments :slight_smile:

FA

I think it depends on your Script Library’s test handler.

I wrote sample JXA script and call my JXA based library on macOS Catalina (10.15.1).
This caller script returned “undefined” not crash.

//caller script


var j = Library("calcLibJS");
var path = Path('/Users/maro/Library/Script Libraries/calcLibJS.scptd');
var finderApp = Application("Finder");
var status = finderApp.exists(path);
console.log("File exists " + status);   //  File exists OK !

var test = j.calcAbs(-10);

//script library


var app = Application.currentApplication();
app.includeStandardAdditions = true;

a1Res = calcAtan2(10,20);  //--> 0.4636476090008061
a2Res = calcAbs(-10);  //--> 10
a3Res = calcAcos(-1); //--> 3.141592653589793
a4Res = calcAcosh(10); //--> 2.993222846126381

function calcAbs(numA){
	return  Math.abs(numA)
}

function calcAtan2(numA,numB){
	return Math.atan2(numA, numB)
}

function calcAcos(numA){
	return Math.acos(numA)
}

function calcAcosh(numA){
	return Math.acosh(numA)
}

function calcAsin(numA){
	return Math.asinh(numA)
}

Model: Mac mini 2014
AppleScript: 1.1
Browser: Safari 605.1.15
Operating System: macOS 10.14

Hi. Welcome to MacScripter.

I know nothing at all about JXA (apart from what I’ve been researching this morning!), but your test script is loading the library before checking that the library file exists! Also, it doesn’t compile with the full stop after ‘console.log("File exists " + status)’.

Obviously the first thing to try would be to run just the first line of the test script. If the Library file doesn’t exist, you’ll get a message telling you so. If Script Editor crashes at that point, there’s some terrible problem with trying to load the library.

Other things to try would be testing with a different function from the library and checking the isLoaded() function to make sure its code is beyond reproach.

One thing I’ve noticed in Mojave is that if a JXA library contains any “top level” code (ie. not in a function), this is executed first the first time one of the functions is called after the library’s loaded. It may be worth checking for any faulty top-level code in the library too.

Hi,

Thanks for your answers and your time, here some precisions perhaps:

the code

var path = Path(‘/Users/maro/Library/Script Libraries/jxalibtotest.scpt’);
var finderApp = Application(“Finder”);
var status = finderApp.exists(path);
console.log("File exists " + status); // File exists OK !

was just a test to verify that the library was found (anyway if it was not the case ScriptEditor would have complained), it was not there in the initial script who was running fine in Mojave.

If I don’t call var test = j.isLoaded() there is no crash so the crash is about the calling of the function (?) or the execution of the function called (?)

Yes, there is a few “top level code” in the library but it ran as this in Mojave so it is weird if that it is the problem. And I tried with just a simple function in another library and it was the same crash!

[TO maro]
What was the context of your test ? For me, I use Script Editor as I used to in Mojave.
ScriptEditor is crashing when I execute the script and go back to Finder !

[TO maro]

I notice that you used a compiled script (.scptd file) so I tried the same and yes, no more crash but it returns ‘undefined’. => It’ weird !!

On Mojave the 2 are working fine (.scpt and .scptd)

Oops!! OK it works fine with a compiled script (.scptd file)
you have to console.log(test) to see the result

console.log(test) => true (for my code, your code should display 10. :slight_smile:

Well, I don’t understand why under Catalina a library script has to be compiled to work (under ScriptEditor)
Anyway it’s a workaround…

Thanks!