Here is a scripted version of the 3 action steps that I previously mentioned:
Zoom("actualPixels");
Zoom("zoomOut");
Zoom("zoomOut");
function Zoom(menuCommand) {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "menuItemClass" ), s2t( "menuItemType" ), s2t( menuCommand ));
descriptor.putReference( s2t( "null" ), reference );
executeAction(s2t( "select" ), descriptor, DialogModes.NO);
}
@Stephen Marsh good trick!
I decided to check if it is possible to directly set the zoom and the position of the center of the image (i.e. if it is possible to make it work in any case, even with overscroll enabled). Maybe someone will need this code:
#target photoshop
var s2t = stringIDToTypeID,
zoom = 0.5;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('resolution'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var res = executeActionGet(r).getInteger(p);
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('width'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var docW = executeActionGet(r).getDouble(p) * res / 72;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('height'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var docH = executeActionGet(r).getDouble(p) * res / 72;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('zoom'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
(d = new ActionDescriptor()).putReference(s2t('null'), r);
(d1 = new ActionDescriptor()).putUnitDouble(s2t('zoom'), s2t('percentUnit'), zoom);
d.putObject(s2t('to'), p, d1);
executeAction(s2t('set'), d, DialogModes.NO);
(r = new ActionReference).putProperty(s2t('property'), s2t('center'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
(d = new ActionDescriptor).putReference(s2t('target'), r);
(d1 = new ActionDescriptor()).putUnitDouble(s2t('horizontal'), s2t('distanceUnit'), docW * zoom / 2);
d1.putUnitDouble(s2t('vertical'), s2t('distanceUnit'), docH * zoom / 2);
d.putObject(s2t('to'), s2t('center'), d1);
executeAction(s2t('set'), d, DialogModes.NO);