Skip to main content
jonohunt
Known Participant
January 15, 2019
Answered

Zoom in and resize window?

  • January 15, 2019
  • 1 reply
  • 1999 views

I found an existing script to zoom in (to whatever level you set it at) with the current image/document.

main();

function main(){

// Change the value between the parentheses below

// into your desired percentage:

setZoomLevel(500);

// Leave the code below unchanged

function setZoomLevel(zoom){

if(zoom < 1) zoom =1;

var ref = new ActionReference();

ref.putEnumerated(charIDToTypeID(\"capp\"), charIDToTypeID(\"Ordn\"), charIDToTypeID(\"Trgt\"));

var getScreenResolution = executeActionGet(ref).getObjectValue(stringIDToTypeID('unitsPrefs')).getUnitDoubleValue(stringIDToTypeID('newDocPresetScreenResolution'))/72;

var docResolution = activeDocument.resolution;

activeDocument.resizeImage(undefined, undefined, getScreenResolution/(zoom/100), ResampleMethod.NONE);

var desc = new ActionDescriptor();

ref = null;

ref = new ActionReference();

ref.putEnumerated(charIDToTypeID(\"Mn  \"), charIDToTypeID(\"MnIt\"), charIDToTypeID('PrnS'));

desc.putReference(charIDToTypeID(\"null\"), ref);

executeAction(charIDToTypeID(\"slct\"), desc, DialogModes.NO);

activeDocument.resizeImage(undefined, undefined, docResolution, ResampleMethod.NONE);};};

I'm wondering if it's possible to modify the script so that it also resizes the window when zooming?

i.e. the equivalent on pressing Command Option = or checking 'Zoom Resizes Windows' in Photoshop's preferences.

This topic has been closed for replies.
Correct answer JJMack

Zooming changing Photoshop image windows size is a Photoshop preference. You can set it either way in and actions and scripts. And you can use menu items in actions and scripts like the zoom in and zoom out and view actual pixels. Some other menu items also change Photoshop image windows size like fit on screen  and full screens mode.

#target photoshop

//

// test.jsx

//

//

// Generated Tue Jan 15 2019 22:43:36 GMT-0500

//

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

//

// Test

//

//

//==================== TestAction ==============

//

function TestAction() {

  // Set

  function step1(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putProperty(cTID('Prpr'), sTID("toolsPreferences"));

    ref1.putEnumerated(cTID('capp'), cTID('Ordn'), cTID('Trgt'));

    desc1.putReference(cTID('null'), ref1);

    var desc2 = new ActionDescriptor();

    desc2.putBoolean(cTID('RWOZ'), false);

    desc1.putObject(cTID('T   '), sTID("toolsPreferences"), desc2);

    executeAction(cTID('setd'), desc1, dialogMode);

  };

  // Set

  function step2(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putProperty(cTID('Prpr'), sTID("toolsPreferences"));

    ref1.putEnumerated(cTID('capp'), cTID('Ordn'), cTID('Trgt'));

    desc1.putReference(cTID('null'), ref1);

    var desc2 = new ActionDescriptor();

    desc2.putBoolean(cTID('RWOZ'), true);

    desc1.putObject(cTID('T   '), sTID("toolsPreferences"), desc2);

    executeAction(cTID('setd'), desc1, dialogMode);

  };

  // Select

  function step3(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('ZmIn'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step4(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('ZmIn'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step5(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('FtOn'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step6(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('ZmOt'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step7(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("screenModeFullScreenWithMenubar"));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step8(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("screenModeFullScreen"));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step9(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("screenModeStandard"));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  step1();      // Set

  step2();      // Set

  step3();      // Select

  step4();      // Select

  step5();      // Select

  step6();      // Select

  step7();      // Select

  step8();      // Select

  step9();      // Select

};

// EOF

"test.jsx"

// EOF

1 reply

JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
January 16, 2019

Zooming changing Photoshop image windows size is a Photoshop preference. You can set it either way in and actions and scripts. And you can use menu items in actions and scripts like the zoom in and zoom out and view actual pixels. Some other menu items also change Photoshop image windows size like fit on screen  and full screens mode.

#target photoshop

//

// test.jsx

//

//

// Generated Tue Jan 15 2019 22:43:36 GMT-0500

//

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

//

// Test

//

//

//==================== TestAction ==============

//

function TestAction() {

  // Set

  function step1(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putProperty(cTID('Prpr'), sTID("toolsPreferences"));

    ref1.putEnumerated(cTID('capp'), cTID('Ordn'), cTID('Trgt'));

    desc1.putReference(cTID('null'), ref1);

    var desc2 = new ActionDescriptor();

    desc2.putBoolean(cTID('RWOZ'), false);

    desc1.putObject(cTID('T   '), sTID("toolsPreferences"), desc2);

    executeAction(cTID('setd'), desc1, dialogMode);

  };

  // Set

  function step2(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putProperty(cTID('Prpr'), sTID("toolsPreferences"));

    ref1.putEnumerated(cTID('capp'), cTID('Ordn'), cTID('Trgt'));

    desc1.putReference(cTID('null'), ref1);

    var desc2 = new ActionDescriptor();

    desc2.putBoolean(cTID('RWOZ'), true);

    desc1.putObject(cTID('T   '), sTID("toolsPreferences"), desc2);

    executeAction(cTID('setd'), desc1, dialogMode);

  };

  // Select

  function step3(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('ZmIn'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step4(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('ZmIn'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step5(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('FtOn'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step6(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('ZmOt'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step7(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("screenModeFullScreenWithMenubar"));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step8(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("screenModeFullScreen"));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  // Select

  function step9(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("screenModeStandard"));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  step1();      // Set

  step2();      // Set

  step3();      // Select

  step4();      // Select

  step5();      // Select

  step6();      // Select

  step7();      // Select

  step8();      // Select

  step9();      // Select

};

// EOF

"test.jsx"

// EOF

JJMack
jonohunt
jonohuntAuthor
Known Participant
January 16, 2019

That's very helpful, thanks a lot!