I wrote it in CS6 EXTENDED, but now tried in 19.1.3 version and it works too however you are right as I mistaken height with width. Now I corrected order, so layers won't be based on width, but height length. Additionally I added 'locked' layers case. So each time script meets them, they will be bypassed. Processing selected layers only version I will do a little later. Change:
resize(s = 600 / ((b = bounds)[2] - b[0]) * 100, s)
to
if (!positionLocked) resize(s = 600 / ((b = bounds)[3] - b[1]) * 100, s)
Here is mainly Action Manager ver. that does the same like previous one with correction (but still with no selected layers):
function sTT(v) {return stringIDToTypeID(v)}
function adl(v) {
(ref = new ActionReference()).putEnumerated
(sTT(v), sTT('ordinal'), sTT('targetEnum'))
}
adl('application'); if (typeIDToStringID(executeActionGet(ref)
.getEnumerationValue(sTT('rulerUnits'))) != 'rulerPixels')
preferences.rulerUnits = Units.PIXELS
adl('document'), len = executeActionGet(ref).getInteger(sTT('numberOfLayers'))
for(i = 1; i <= len;) {
(ref = new ActionReference()).putIndex(sTT('layer'), i++)
if (typeIDToStringID((dsc = executeActionGet(ref))
.getEnumerationValue(sTT(lS = 'layerSection'))) == lS + 'Content') {
(lst = new ActionList()).putReference(ref), dsc.putList(sTT('null'), lst)
function prtct(v) {
return dsc.getObjectValue(sTT('layerLocking')).getBoolean(sTT(v))
}
if (!prtct('protectPosition') && !prtct('protectAll')) {
bnds = dsc.getObjectValue(sTT('bounds'))
if (!dsc.getBoolean(sTT('visible'))) {
executeAction(sTT('show'), dsc, DialogModes.NO)
}
(ref = new ActionReference()).putIndex(sTT('layer'), i - 1);
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref)
executeAction(sTT('select'), dsc, DialogModes.NO)
function h(v) {return bnds.getUnitDoubleValue(sTT(v))}
if ((s = 600 / (h('top') - h('bottom')) * 100) < Infinity) {
function wh(v) {
dsc.putUnitDouble(sTT(v), sTT('percentUnit'), s)
}
wh('width'), wh('height'), executeAction
(sTT('transform'), dsc, DialogModes.NO)
}
}
}
}
In previous script I prevented also transforming while processing empty layer. Here's a version where you can select layers:
function adl(v1, v2) {
eval("(ref = new ActionReference()).put" + (!v2 ? "Enumerated" : "Index")
+ "(sTT(v1), " + (!v2 ? "sTT('ordinal'), sTT('targetEnum')" : I) + ")")
}
function prtct(v) {
return dsc.getObjectValue(sTT('layerLocking')).getBoolean(sTT(v))
}
function prcs(v) {
adl('layer', v); if (typeIDToStringID((dsc = executeActionGet(ref))
.getEnumerationValue(sTT(lS = 'layerSection'))) == lS + 'Content') {
(lst2 = new ActionList()).putReference(ref), dsc.putList(sTT('null'), lst2)
if (!prtct('protectPosition') && !prtct('protectAll')) {
bnds = dsc.getObjectValue(sTT('bounds'))
if (!dsc.getBoolean(sTT('visible'))) {
executeAction(sTT('show'), dsc, DialogModes.NO)
}
if (v) (ref = new ActionReference()).putIndex(sTT('layer'), I);
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref)
executeAction(sTT('select'), dsc, DialogModes.NO)
function h(v) {return bnds.getUnitDoubleValue(sTT(v))}
if ((s = 600 / (h('top') - h('bottom')) * 100) < Infinity) {
function wh(v) {
dsc.putUnitDouble(sTT(v), sTT('percentUnit'), s)
}
wh('width'), wh('height'), executeAction
(sTT('transform'), dsc, DialogModes.NO)
}
}
}
}
function sTT(v) {return stringIDToTypeID(v)} $.level = 0
adl('application'); if (typeIDToStringID(executeActionGet(ref)
.getEnumerationValue(sTT('rulerUnits'))) != 'rulerPixels')
preferences.rulerUnits = Units.PIXELS
try{
(ref = new ActionReference()).putIdentifier(sTT('layer'), 1)
bG = !(executeActionGet(ref)).getBoolean(sTT('background'))
}
catch (err) {bG = 1}
adl('document'), tL = sTT('targetLayers')
if ((dsc = executeActionGet(ref)).hasKey(tL)) {
for(lst1 = dsc.getList(tL), i = 0; i < lst1.count; i++) {
I = lst1.getReference(i).getIndex() + bG, prcs(true)
}
}
else prcs()