Skip to main content
Andrew Bold
Known Participant
January 14, 2023
Answered

A script that replaces the ctr+0 hotkeys.

  • January 14, 2023
  • 1 reply
  • 926 views

In the process of semi-automatic processing, there is a pause in my actions, where I spot-correct some points.
The situation is that after manipulation the image may be in different places in Photoshop.

 

Of course in this pause you can press ctr+tab, ctr+0, but you have to do it constantly and with a very large number of photos.

 

In this regard, I'm looking for a script that will be analogous to ctr+0 or will make the image scale 50% (this value is good for my purposes).

 

This topic has been closed for replies.
Correct answer jazz-y

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);

1 reply

Stephen Marsh
Community Expert
Community Expert
January 14, 2023

It is possible in an action, but it takes 3 steps.

 

Here it is in a script:

 

/* https://community.adobe.com/t5/photoshop-ecosystem-discussions/image-view/m-p/10650951 */

setZoom(50); // as percent

function setZoom(zoom) { 
   cTID = function (s) {
      return app.charIDToTypeID(s);
   }; // from xbytor
   var docRes = activeDocument.resolution;
   activeDocument.resizeImage(undefined, undefined, 72 / (zoom / 100), ResampleMethod.NONE);
   var desc = new ActionDescriptor();
   var ref = new ActionReference();
   ref.putEnumerated(cTID("Mn  "), cTID("MnIt"), cTID('PrnS'));
   desc.putReference(cTID("null"), ref);
   executeAction(cTID("slct"), desc, DialogModes.NO);
   activeDocument.resizeImage(undefined, undefined, docRes, ResampleMethod.NONE);
}
Andrew Bold
Known Participant
January 14, 2023

Hi @Stephen Marsh ! The script does do 50%, but it doesn't center the image the way the ctrl+0 key combination does. The picture still stays in an arbitrary place

 

 

Stephen Marsh
Community Expert
Community Expert
January 14, 2023

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);
}