Monday, October 26, 2020

#1 2019-11-16 03:42:19 pm

fa65
Member
Registered: 2019-03-14
Posts: 4

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 smile

FA


Filed under: JXA Catalina

Offline

 

#2 2019-11-17 08:50:27 am

maro
Member
From:: Nerima, Tokyo, Japan
Registered: 2004-05-30
Posts: 130
Website

Re: JXA Library functions on Catalina make script editor crash every time

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

Applescript:


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

Applescript:


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


I wrote thousands of AppleScript to realize my idea. Natural language interface, voice recognition commander and so on. Though my mother toungue is strange language, Japanese, my most frequently write language is AppleScript. I believe it is for making things easy and powerful.


Filed under: JXA, macOS Catalina

Offline

 

#3 2019-11-17 09:13:36 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5299

Re: JXA Library functions on Catalina make script editor crash every time

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.


NG

Offline

 

#4 2019-11-17 11:32:19 am

fa65
Member
Registered: 2019-03-14
Posts: 4

Re: JXA Library functions on Catalina make script editor crash every time

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 !

Offline

 

#5 2019-11-17 11:42:54 am

fa65
Member
Registered: 2019-03-14
Posts: 4

Re: JXA Library functions on Catalina make script editor crash every time

[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)

Offline

 

#6 2019-11-17 12:19:38 pm

fa65
Member
Registered: 2019-03-14
Posts: 4

Re: JXA Library functions on Catalina make script editor crash every time

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. 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!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)