Does this example help?
https://github.com/simo101/Mendix-Count-Application-Objects/blob/master/script.ts
Simon, thank you for the link.
We can confirm that this script indeed works. We could open and count objects of our own application.
Thanks again :)