Skip to content

Comment on JXA’s Parenthesis Paradoxparent

Comments

I think this comes down to how apple events (the underlying mechanism used for applescript) works internally, which is basically rpc + relational queries. The only good documentation I've found on how this works is at [1]

In order to use appscript effectively, you will need to understand the differences between the Apple event and Python object systems.
In contrast to the familiar object-oriented approach of other inter-process communication systems such as COM and Distributed Objects, Apple event IPC is based on a combination of remote procedure calls and first-class queries - somewhat analogous to using XPath over XML-RPC.

I think the developer of appscript has posted about this on HN a few times in the past.

Btw the article's example is the following in py-appscript:

   app('System Events').processes[(its.visible == True).AND(its.name.beginswith('M'))].name.get()
Although even this might be a bit misleading since the array access isn't actually accessing any array but from what I understand is just syntactic sugar to build up the query (the apple-event equivalent of a DOM selector or xpath). Or maybe if it's easier you can treat it as lazy evaluation, until the actual .get() fires the rpc

[1] http://appscript.sourceforge.net/py-appscript/doc_3x/appscri...

I’m thinking with a little tomfoolery you could get the python version to mimic the parentheses paradox without having to overload the array access operator. I’d have to think about how much the call order would matter and how much hackery it would take if it did. I think it could be made to work by abusing the attribute lookup function, I did something similar in a project but it didn’t pass information from the general to specific (if that’s even required for this).

The real question is if you’d want to as it wouldn’t be very pythonic.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.