This is the modified script. Thank you Uwe, it wouldn't have been possible without your help. It needs a little more works, like group and ungrouping, the bounds of actual page (might not be necessary, since this is mostly for single page document). but the main issue has been addressed.
/**
* @@@BUILDINFO@@@ Scale-with-TransformationMatrix-ADJUST SCALING PERCENTAGE.jsx !Version! Wed Oct 13 2021 18:29:40 GMT+0200
*/
(function()
{
app.doScript
(
scaleSelectedObject ,
ScriptLanguage.JAVASCRIPT ,
[],
UndoModes.ENTIRE_SCRIPT ,
"SCRIPT | Scale Selected Object with ADJUST_SCALING_PERCENTAGE"
);
function scaleSelectedObject()
{
// get width of the
var doc = app.activeDocument;
w = doc.documentPreferences.pageWidth;
// get width of group
var gb = doc.selection[0].visibleBounds;
var groupWidth = gb[3] - gb[1]
var whenScalingProps = app.transformPreferences.properties;
/* ALLOWS TO SCALE EFFECTS AND STROKE*/
app.transformPreferences.properties =
{
whenScaling : WhenScalingOptions.APPLY_TO_CONTENT
};
/* THE WIDTH OF PAGE DIVIDED BY THE WIDTH OF THE GROUP */
var myMatrix = app.transformationMatrices.add();
myMatrix = myMatrix.scaleMatrix( w/groupWidth,w/groupWidth );
/* TRANSFORM THE SELECTED OBJECT */
app.selection[0].transform
(
CoordinateSpaces.INNER_COORDINATES ,
AnchorPoint.BOTTOM_RIGHT_ANCHOR ,
myMatrix
);
app.transformPreferences.properties = whenScalingProps;
};
}());