Unless I am wrong what you can't do in the UI can't also be done by scripting ;-)
You can group objects from distinct pages only if they belong to the same spread.
For instance, if you have a rectangle on page 2 and a rectangle on page 3 in a "facing pages" configuration, this should work:
var doc = app.activeDocument; var r2 = doc.pages.rectangles; // rectangle on page 2 var r3 = doc.pages.rectangles; // rectangle on page 3 // it's better here to handle the parent spread: var g = doc.spreads.groups.add([r2,r3]); // but this may also work: // var g = doc.pages.groups.add([r2,r3]); // var g = doc.pages.groups.add([r2,r3]);
You are so right Marc, I was of course pointing that you can't group objects in different spreads. Sorry for my lack of precision and thank you to you to point this out.