The simplest way to go about that is to use Applescript on Mac or VB on WIndows.
Innovations in Automation
Why is it that VB can do it and js can not? seems to me that they would want to push people toward js vs vb?
I am dissapointed if this is so...
VB is a system wide scripting engine, so you can run it from outside InDesign. You create an InDesign object to address InDesign. This can be done by another application as well.