Thank you, that's really helpful. I've actually come across this error before from another script that someone had the same issue with, but I think couldn't be bothered to go through the steps at his end to help debug it, so I was never able to provide him with a fix.
It is a Mojave JXA bug, where it appears to be incorrectly converting the data types from the sort that JavaScript uses to the sort that C or Objective-C uses. In this case, it appears to be one of the arguments passed to one of the functions that's the problem, and it occurs when that function is invoking another function behind the scenes called NSGetSizeAndAlignment()
, at which point the JavaScript engine is crashing.
I'm don't know for certain which function is the guilty culprit. However, since NSGetSizeAndAlignment()
is an Objective-C Foundation method (starting with "NS..."
), my first guess is that it might be the NSScreen
class that's calling it in order to obtain the dimensions of your display.
My second suspect would be CGRectMake()
, which also deals with arguments that specify the size and position of something on the screen, however "CG..."
functions belong to Core Graphics, and these use Core Foundation data types, which existed before Foundation data types came along, so it would be surprising—but not impossible—if was making use of a Foundation class method, as it's typically the other way round (Foundation class methods calling Core Foundation functions in the background).
Anyway, that's all probably sounds very dry to you. If you're happy to, let's find out if NSScreen
is being naughty... Can you delete the entire text in the JavaScript action, and replace it with this:
ObjC.import('Cocoa');
$.NSScreen.mainScreen.frame.size.height;
Run that action with just those two lines, and let me know what gets stored in the RGBa
variable. It's best to go into Preferences... and delete the current contents of the RGBa
variable first, because I'm hoping that the variable will end up being given the same error message you're getting now, and if there's anything that simply stops the script from running before the action writes out to the variable, it'll contain the same data as before and be misleading false positive test.
If the variable contains the height of your screen, then could you re-run the test with this script instead:
ObjC.import('Cocoa');
$.CGRectMake(10, 10, 1, 1);
If both of those work successfully, then my next step would be to do this test with every single line individually until I get one that throws the error (you can see why the previous user a while back probably just scoffed at this idea and thought "ah, fuck it, I'll find another way", so I don't blame them. But if I had Mojave, I can actually run the script myself in a step-wise fashion using my own debugging routine that would take about a minute to locate the problem, but it's these scripting bugs that Apple are too ambivalent to bother fixing that made me not want to upgrade to Mojave in the first place). Don't do this yourself, but let me know if you're willing and I'll tell you the order in which to test each function as some can't be tested by themselves on a single line and need to be tested in conjunction with another function that first needs vetting before testing it with another, etc. etc.