Skip to main content
dublove
Legend
Nov 4, 2026 4:20 AM UTC
Answered

How to use a script to open an image and skip displaying it at "screen 100%" size, and display it directly at "screen 70%"?

Please, master, study this code again.

I still think this transition is a bit time-consuming.

 

I want to use a script to open an image and display it at 70% of the screen size.

But I found that every time the image is opened, it is displayed at 100% screen size and then switched to 70% size, with a transition in between that takes about 1 second, which is a bit uncomfortable.

May I ask if it is possible to display it directly at 70% screen size after opening it?

 

Also, there is a problem:

when I call this script from Indesign, I often get an error saying that my monitor doesn't have space to park images?

I have searched for solutions:
Cancel the tab to open the document (I think this is inconvenient and not adopted);
Reset workspace. I have tried, but problems still arise.


/** Zoom to 46 % of Fit On Screen Zoom
Stephen Marsh
https://community.adobe.com/questions-712/can-this-script-be-modified-to-fit-46-of-the-screen-1560318
**/
//#target photoshop
// Fit on Screen
var fitDesc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Mn "), charIDToTypeID("MnIt"), charIDToTypeID("FtOn"));

fitDesc.putReference(charIDToTypeID("null"), ref);
executeAction(charIDToTypeID("slct"), fitDesc, DialogModes.NO);

// Read the the current zoom
var docRef = new ActionReference();
docRef.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var docDesc = executeActionGet(docRef);

var fitZoom = docDesc.getDouble(stringIDToTypeID("zoom")) * 100;
// Calculate the target zoom
var FACTOR = 0.70;
var targetZoom = fitZoom * FACTOR;
// Apply the calculated zoom
setZoomLevel(targetZoom);
// Optional confirmation
//alert("Fit zoom: " + Math.round(fitZoom * 10) / 10 + "%\n" + "Target (" + (FACTOR * 100) + "% factor): " + Math.round(targetZoom * 10) / 10 + "%");
///// FUNCTIONS /////
function setZoomLevel(zoomPercent) {
if (zoomPercent < 1) zoomPercent = 1;
var originalRes = activeDocument.resolution;
// Get the screen resolution
var screenRef = new ActionReference();
screenRef.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var screenRes = executeActionGet(screenRef)
.getObjectValue(stringIDToTypeID("unitsPrefs"))
.getUnitDoubleValue(stringIDToTypeID("newDocPresetScreenResolution")) / 72;
// Change the resolution temporarily
activeDocument.resizeImage(undefined, undefined, screenRes / (zoomPercent / 100), ResampleMethod.NONE);
// Zoom to print size
var printDesc = new ActionDescriptor();
var printRef = new ActionReference();
printRef.putEnumerated(charIDToTypeID("Mn "), charIDToTypeID("MnIt"), charIDToTypeID("PrnS"));
printDesc.putReference(charIDToTypeID("null"), printRef);
executeAction(charIDToTypeID("slct"), printDesc, DialogModes.NO);
// Restore the original resolution
activeDocument.resizeImage(undefined, undefined, originalRes, ResampleMethod.NONE);
}

//This sentence can only be placed at the end
try {
executeAction(sTID('imageSize'), undefined, DialogModes.ALL);
} catch (e) { if (e.number != 8007) { alert("Line: " + e.line + "\n\n" + e, "Bug!", true); throw (e); } }

 

    Stephen Marsh
    Stephen MarshCorrect answer
    Community Expert
    Nov 4, 2026 12:00 PM UTC

    ​@Trevor.Dennis - thanks for tagging me in, I had missed this topic.

     

    ​@dublove - try the following alternative code:

     

    /*
    Zoom to 70% of Fit On Screen Zoom
    Stephen Marsh
    https://community.adobe.com/questions-712/how-to-use-a-script-to-open-an-image-and-skip-displaying-it-at-screen-100-size-and-display-it-directly-at-screen-70-1654262
    Original:
    https://community.adobe.com/questions-712/can-this-script-be-modified-to-fit-46-of-the-screen-1560318
    */

    #target photoshop

    var zoomScale = 0.70;

    // Fit on Screen
    app.runMenuItem(charIDToTypeID("FtOn"));

    // Read current (fit) zoom, returned as a fraction (1.0 = 100%)
    var r = new ActionReference();
    r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    var fitZoom = executeActionGet(r).getDouble(stringIDToTypeID("zoom"));

    // Apply the target zoom
    setZoom(fitZoom * zoomScale * 100);


    function setZoom(percent) {
    var d = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("zoom"));
    ref.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    d.putReference(stringIDToTypeID("null"), ref);

    var z = new ActionDescriptor();
    z.putDouble(stringIDToTypeID("zoom"), percent / 100);
    d.putObject(stringIDToTypeID("to"), stringIDToTypeID("zoom"), z);

    executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
    }

     

    8 replies

    Stephen Marsh
    Community Expert
    Stephen MarshCommunity ExpertCorrect answer
    Community Expert
    Nov 4, 2026 12:00 PM UTC

    ​@Trevor.Dennis - thanks for tagging me in, I had missed this topic.

     

    ​@dublove - try the following alternative code:

     

    /*
    Zoom to 70% of Fit On Screen Zoom
    Stephen Marsh
    https://community.adobe.com/questions-712/how-to-use-a-script-to-open-an-image-and-skip-displaying-it-at-screen-100-size-and-display-it-directly-at-screen-70-1654262
    Original:
    https://community.adobe.com/questions-712/can-this-script-be-modified-to-fit-46-of-the-screen-1560318
    */

    #target photoshop

    var zoomScale = 0.70;

    // Fit on Screen
    app.runMenuItem(charIDToTypeID("FtOn"));

    // Read current (fit) zoom, returned as a fraction (1.0 = 100%)
    var r = new ActionReference();
    r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    var fitZoom = executeActionGet(r).getDouble(stringIDToTypeID("zoom"));

    // Apply the target zoom
    setZoom(fitZoom * zoomScale * 100);


    function setZoom(percent) {
    var d = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("zoom"));
    ref.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    d.putReference(stringIDToTypeID("null"), ref);

    var z = new ActionDescriptor();
    z.putDouble(stringIDToTypeID("zoom"), percent / 100);
    d.putObject(stringIDToTypeID("to"), stringIDToTypeID("zoom"), z);

    executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
    }

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Nov 4, 2026 12:12 PM UTC

    Hi ​@Stephen Marsh 

    Thank you very much.

    Still display 100% first, then 70%.
    But the speed is significantly faster than previous versions.
    Perhaps 100% is a necessary step to go through.

    Translate
    D Fosse
    Community Expert
    Community Expert
    Nov 4, 2026 9:22 AM UTC

    The “not enough screen space” error has often been caused by placing the toolbar on the right-hand side of the screen. It seems Photoshop still tries to put the image right of the toolbar. I haven’t tested this myself, but we’ve seen several cases here. Yes, you can see this as a shortcoming but it’s just the way it seems to be. It’s possible the reverse may happen with panels.

    And just to clear up one misunderstanding: 100% has nothing to do with on-screen size. It just means one image pixel is represented by exactly one physical screen pixel, regardless of document size. There is AFAIK no code in Photoshop that calculates zoom ratios relative to screen size, aside from the hard-coded “Fit to Screen”. As Eugene implies, that’s the only fixed point, and percentages of screen size will have to start there.

    If the document is too big to display at 100% - too many pixels - then Photoshop goes down to the next cached zoom ratio in the “image pyramid”, corresponding to the number of Cache Levels set in Preferences > Performance.

    Translate
    Trevor.Dennis
    Community Expert
    Community Expert
    Nov 4, 2026 8:29 PM UTC

    That’s interesting Dag.  I have just tried to make it happen with Windows 11 and the toolbar location does not appear to have any affect on how the document window displays.  I tried it with Overscroll on and off with a restart, and found no difference.  I am often moving panels about either to take screen shots or simply to minimise cursor movement.  I can’t remember seeing any different behaviour based on panel locaion.

    Translate
    Community Expert
    Nov 4, 2026 7:44 AM UTC

    I think there might be a better way of handling the zoom without changing the document resolution.

    Photoshop has an Action Manager command called `setPanZoom`, which can set a zoom level directly with animation disabled. This might be worth testing as an alternative to the current approach, which temporarily changes the image resolution, uses Print Size and then restores the resolution.

    The complication is that you're calculating 70% of Fit on Screen, rather than a fixed 70% zoom. To get that exact percentage, Photoshop first needs to establish what Fit on Screen would be for the current document window.

    So I think we could reduce the number of operations and possibly eliminate the visible zoom animation, but I'm not certain we can completely prevent Photoshop from displaying the document at its initial zoom when opening it.

    Regarding the error about not having enough room to dock the document, I found a similar report involving Photoshop 26.5 and automated image opening. In that case, reverting to 26.4.1 resolved the issue.

    Could you confirm which version of Photoshop you're using, whether this happens when opening the image directly in Photoshop, and whether you're using multiple monitors?

    Translate
    dublove
    dubloveAuthor
    Legend
    Nov 4, 2026 9:47 AM UTC

    Mine is the latest, and if necessary, I will revert to 26.4.1

    Translate
    Trevor.Dennis
    Community Expert
    Community Expert
    Nov 4, 2026 5:40 AM UTC

    ​@Stephen Marsh will no doubt be along to help if he is able.  

    Translate