In a scenario where I have a TextFrame (TF) with content, and there is lots of empty space at the bottom of the TF. How can I accomplish in InDesign JS the equivalent of 'user interaction of doubleclicking on the bottom center control point to snap TF bottom to just below text' in script below?
var testDoc = app.documents.add();
var testPage = app.activeWindow.activePage;
var tf = testPage.textFrames.add();
tf.geometricBounds = [0, 0, 250, 100];
tf.contents = "lalalalal";
Bonus question : Is there a simple universal (or general, but not absolute) method for this for any ui object interaction?
No, you cannot really simulate any clicks in the UI with ExtendScript. However, you can simply simulate that behavior by setting the bottom coordinate to the baseline of the text frame's last insertion point.
var tf = app.selection[0];
var gb = tf.geometricBounds;
gb[2] = tf.insertionPoints[-1].baseline;
tf.geometricBounds = gb;