As I understand it, this code worked before, but doesn’t work since Big Sur. The same request is posted on the stack.overflow site.
I would provide a solution, but my account is temporarily blocked there. A well-known bozo has settled there, who does not hesitate to appropriate other people’s answers (solutions). When I was outraged, I was blocked for 1 week. :lol:
@adib, I apologize for the delay in responding. I just wanted to draw attention to the dishonesty of one user from the above site. I was forced to do it here. Against you, I certainly have nothing.
I have Catalina, but if the following solution satisfies you (at Big Sur), then I will be only too glad. Your question is of course about JXA, but I would venture to post the answer here. In order not to tire you and myself by waiting for 3 days (for deblocking my account).