Skip to main content
dublove
Legend
April 18, 2025
Answered

Please, Help me modify this script, thanks.

  • April 18, 2025
  • 3 replies
  • 771 views

This script is used for ps to automatically zoom to 100% after opening an image.
Now I want to add a function: after zooming in 100%, pop up the image size setting dialog box.

I'm going to change the width of the image。
Thank you very much.

setZoom (100);

function setZoom( zoom ) {
   cTID = function(s) { return app.charIDToTypeID(s); };
   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 );
}
This topic has been closed for replies.
Correct answer Stephen Marsh

@dublove

 

The new forum software nested replies are often collapsed, which I don’t like:

 

 

// Print Size
var idslct = charIDToTypeID( "slct" );
var desc244 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idMn = charIDToTypeID( "Mn " );
var idMnIt = charIDToTypeID( "MnIt" );
var idPrnS = charIDToTypeID( "PrnS" );
ref1.putEnumerated( idMn, idMnIt, idPrnS );
desc244.putReference( idnull, ref1 );
executeAction( idslct, desc244, DialogModes.NO );

 

And:

 

// Print Size
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "menuItemClass" ), s2t( "menuItemType" ), s2t( "printSize" ));
descriptor.putReference( c2t( "null" ), reference );
executeAction( s2t( "select" ), descriptor, DialogModes.NO );

 

3 replies

dublove
dubloveAuthor
Legend
May 4, 2026

Hi ​@Stephen Marsh  

Thank you very much.

I don't seem to be able to open this URL.
I know how to add an event.
Can't we achieve this by modifying the code?
For example, by changing this part to display “Print Size”:
activeDocument.suspendHistory(“Set Zoom to 100%”, “setZoom(100)”);

Stephen Marsh
Community Expert
Community Expert
May 4, 2026

You can simply do this via an action, using the “insert menu item command” to insert the Print Size command.

 

The Script Events Manager can then automatically run this action on document open event.

 

Or one of the previous script codes that I recently posted for Print Size can be used rather than the action.

 

As I previously wrote, I don’t see any benefit in updating the old code you mentioned as it is so different.

dublove
dubloveAuthor
Legend
May 4, 2026

Sometimes I need to add code to scripts in InDesign.
So I’d like to use code.

Or one of the previous script codes that I recently posted for Print Size can be used rather than the action.

Where is it?

dublove
dubloveAuthor
Legend
May 3, 2026

Hi ​@Stephen Marsh 

If I want to display “Print Size,”
how do I modify this:
activeDocument.suspendHistory(“Set Zoom to 100%”, “setZoom(100)”);

Stephen Marsh
Community Expert
Community Expert
May 4, 2026

@dublove 

 

I’m not sure if it makes sense to update the old script to use the print size command?

 

Forgetting the old script for now, all you need to do is use this raw SL code:

 

// Print Size
var idslct = charIDToTypeID( "slct" );
var desc244 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idMn = charIDToTypeID( "Mn " );
var idMnIt = charIDToTypeID( "MnIt" );
var idPrnS = charIDToTypeID( "PrnS" );
ref1.putEnumerated( idMn, idMnIt, idPrnS );
desc244.putReference( idnull, ref1 );
executeAction( idslct, desc244, DialogModes.NO );

 

Or this “cleaned” version:

 

// Print Size
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "menuItemClass" ), s2t( "menuItemType" ), s2t( "printSize" ));
descriptor.putReference( c2t( "null" ), reference );
executeAction( s2t( "select" ), descriptor, DialogModes.NO );

 

Let me know if you need to do more than this in a script.

dublove
dubloveAuthor
Legend
May 4, 2026

@Stephen Marsh 

I want the image to appear more true to life in terms of size when I open it in Photoshop.

For example, if the ruler in Photoshop shows 100 mm, I can use a ruler to measure the actual size on the screen, and the two should be very close.
It should look just like a real 100 mm object.

Inspiring
April 18, 2025

See if this works for you

 

setZoom (100);

function setZoom( zoom ) {
   cTID = function(s) { return app.charIDToTypeID(s); };
   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 );
}

sTID = function(s) { return app.stringIDToTypeID(s); };
  try {
    executeAction(sTID('imageSize'), undefined, DialogModes.ALL);
  }catch (e) { if (e.number!=8007) { alert("Line: "+e.line+"\n\n"+e,"Bug!",true); throw(e); } }  
dublove
dubloveAuthor
Legend
April 18, 2025

Fantastic, very impressive.
Thank you very much.