• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

A script that replaces the ctr+0 hotkeys.

Participant ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

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

 

IMG_20230114_110508_055.jpg

IMG_20230114_110507_565.jpg

TOPICS
Actions and scripting

Views

624

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Jan 14, 2023 Jan 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 
...

Votes

Translate

Translate
Guide , Jan 14, 2023 Jan 14, 2023

@Stephen_A_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).getI
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

Hi @Stephen_A_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

 

Andry_J_0-1673695973046.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

@Stephen_A_Marsh  , thank you very much, your both codes started working fine after I turned off "overscroll".

Thanks @D Fosse  for that tip!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

LATEST
quote

@Stephen_A_Marsh good trick!

 

Full credit to @xbytor2 ! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

From how you describe it, it sounds like you may just need to uncheck "overscroll" in Preferences?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines