I'm trying to convert this Applescript to Javascript for Automation.
Is there anyone who can help to write the line bellow in Javascript for Automation?
set thisTable to the first table whose class of selection range is range
Appreciate any help!
I'm trying to convert this Applescript to Javascript for Automation.
Is there anyone who can help to write the line bellow in Javascript for Automation?
set thisTable to the first table whose class of selection range is range
Appreciate any help!
This will require the use of a
whoseclause for querying the element array of tables in the selected sheet—essentially, you want to find allTableobjects whoseselectionRangeattribute is notnull(which is analogous to asserting that its class isrange). Unfortunately, there seems to be a bug in JXA that prevents comparisons withnull. So while it would be optimal to simply check_not: [{ selectionRange: null }]in the code below, I found that that approach did not work. Instead, the following appears (albeit not particularly elegantly) to do what you're looking for:This is a pretty hacky approach (it relies on the fact that
selectionRange.nameisn't even a valid key for non-selected tables), but given the buggy state of JXA, it may be the best one can do.Further Reading:
whoseclauseswhosenotationwhosefilter operators