When working with an image in Photoshop, I'd like to have a simple keyboard shortcut, like in Photoshop shortcut for File, Save As, Format: PNG or JPG, Save, OK, that automatically does:

  • Export > Export As or Export > Save For Web
  • Resize to biggest dimension = 600px (either width or height)
  • Add suffix _600.jpg to filename

How to do that?

I'm not sure how to edit a recorded macro to do that (add the suffix and choose 600px for the biggest dimension).

Example: you open myphoto.png, you press F6 and then you automatically get myphoto_600.jpg.


1 Answer 1


Here's the modified version of the script that @Tetsujin has mentioned. It'll save a 600px jpg (you can set the max size in the targetSize variable) to the folder of the active document with a name_600.jpg:

function main()
  var targetSize = 600;
  var fileName = activeDocument.name.replace(/\.[^.]+$/g, "");
  var width = activeDocument.width.as('px');
  var height = activeDocument.height.as('px');

  var filePath, scale, ratio;

    filePath = activeDocument.path;
  catch (e)
    alert('File was never saved, aborting');
    return false;

  ratio = width / height;

  scale = ratio >= 1 ? targetSize / width : targetSize / height;

  saveForWeb(fileName + "_" + targetSize + ".jpg", filePath, 90, scale * 100);

  function saveForWeb(fileName, filePath, quality, scale)
    function cTID(s)
      return app.charIDToTypeID(s);

    function sTID(s)
      return app.stringIDToTypeID(s);

    var desc21 = new ActionDescriptor();
    var desc22 = new ActionDescriptor();
    desc22.putEnumerated(cTID('Op  '), cTID('SWOp'), cTID('OpSa'));
    desc22.putBoolean(cTID('DIDr'), true);
    desc22.putPath(cTID('In  '), new File(filePath)); // file path
    desc22.putString(cTID('ovFN'), fileName); // file name
    desc22.putEnumerated(cTID('Fmt '), cTID('IRFm'), cTID('JPEG'));
    desc22.putBoolean(cTID('Intr'), false);
    desc22.putInteger(cTID('Qlty'), quality); // quality
    desc22.putInteger(cTID('QChS'), 0);
    desc22.putInteger(cTID('QCUI'), 0);
    desc22.putBoolean(cTID('QChT'), false);
    desc22.putBoolean(cTID('QChV'), false);
    desc22.putBoolean(cTID('Optm'), true);
    desc22.putInteger(cTID('Pass'), 1);
    desc22.putDouble(cTID('blur'), 0.000000);
    desc22.putBoolean(cTID('Mtt '), false);
    desc22.putBoolean(cTID('EICC'), false);
    desc22.putInteger(cTID('MttR'), 255);
    desc22.putInteger(cTID('MttG'), 255);
    desc22.putInteger(cTID('MttB'), 255);
    desc22.putUnitDouble(cTID('HScl'), cTID('#Pxl'), scale); // scale
    desc22.putUnitDouble(cTID('VScl'), cTID('#Pxl'), scale); // scale
    desc22.putBoolean(cTID('SHTM'), false);
    desc22.putBoolean(cTID('SImg'), true);
    desc22.putEnumerated(cTID('SWsl'), cTID('STsl'), cTID('SLAl'));
    desc22.putEnumerated(cTID('SWch'), cTID('STch'), cTID('CHsR'));
    desc22.putEnumerated(cTID('SWmd'), cTID('STmd'), cTID('MDCC'));
    desc22.putBoolean(cTID('ohXH'), false);
    desc22.putBoolean(cTID('ohIC'), true);
    desc22.putBoolean(cTID('ohAA'), true);
    desc22.putBoolean(cTID('ohQA'), true);
    desc22.putBoolean(cTID('ohCA'), false);
    desc22.putBoolean(cTID('ohIZ'), true);
    desc22.putEnumerated(cTID('ohTC'), cTID('SToc'), cTID('OC03'));
    desc22.putEnumerated(cTID('ohAC'), cTID('SToc'), cTID('OC03'));
    desc22.putInteger(cTID('ohIn'), -1);
    desc22.putEnumerated(cTID('ohLE'), cTID('STle'), cTID('LE03'));
    desc22.putEnumerated(cTID('ohEn'), cTID('STen'), cTID('EN00'));
    desc22.putBoolean(cTID('olCS'), false);
    desc22.putEnumerated(cTID('olEC'), cTID('STst'), cTID('ST00'));
    desc22.putEnumerated(cTID('olWH'), cTID('STwh'), cTID('WH01'));
    desc22.putEnumerated(cTID('olSV'), cTID('STsp'), cTID('SP04'));
    desc22.putEnumerated(cTID('olSH'), cTID('STsp'), cTID('SP04'));
    var list3 = new ActionList();
    var desc23 = new ActionDescriptor();
    desc23.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC00'));
    list3.putObject(cTID('SCnc'), desc23);
    var desc24 = new ActionDescriptor();
    desc24.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC19'));
    list3.putObject(cTID('SCnc'), desc24);
    var desc25 = new ActionDescriptor();
    desc25.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC28'));
    list3.putObject(cTID('SCnc'), desc25);
    var desc26 = new ActionDescriptor();
    desc26.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC24'));
    list3.putObject(cTID('SCnc'), desc26);
    var desc27 = new ActionDescriptor();
    desc27.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC24'));
    list3.putObject(cTID('SCnc'), desc27);
    var desc28 = new ActionDescriptor();
    desc28.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC24'));
    list3.putObject(cTID('SCnc'), desc28);
    desc22.putList(cTID('olNC'), list3);
    desc22.putBoolean(cTID('obIA'), false);
    desc22.putString(cTID('obIP'), "");
    desc22.putEnumerated(cTID('obCS'), cTID('STcs'), cTID('CS01'));
    var list4 = new ActionList();
    var desc29 = new ActionDescriptor();
    desc29.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC01'));
    list4.putObject(cTID('SCnc'), desc29);
    var desc30 = new ActionDescriptor();
    desc30.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC20'));
    list4.putObject(cTID('SCnc'), desc30);
    var desc31 = new ActionDescriptor();
    desc31.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC02'));
    list4.putObject(cTID('SCnc'), desc31);
    var desc32 = new ActionDescriptor();
    desc32.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC19'));
    list4.putObject(cTID('SCnc'), desc32);
    var desc33 = new ActionDescriptor();
    desc33.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC06'));
    list4.putObject(cTID('SCnc'), desc33);
    var desc34 = new ActionDescriptor();
    desc34.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC24'));
    list4.putObject(cTID('SCnc'), desc34);
    var desc35 = new ActionDescriptor();
    desc35.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC24'));
    list4.putObject(cTID('SCnc'), desc35);
    var desc36 = new ActionDescriptor();
    desc36.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC24'));
    list4.putObject(cTID('SCnc'), desc36);
    var desc37 = new ActionDescriptor();
    desc37.putEnumerated(cTID('ncTp'), cTID('STnc'), cTID('NC22'));
    list4.putObject(cTID('SCnc'), desc37);
    desc22.putList(cTID('ovNC'), list4);
    desc22.putBoolean(cTID('ovCM'), false);
    desc22.putBoolean(cTID('ovCW'), true);
    desc22.putBoolean(cTID('ovCU'), true);
    desc22.putBoolean(cTID('ovSF'), true);
    desc22.putBoolean(cTID('ovCB'), true);
    desc22.putString(cTID('ovSN'), "images");
    desc21.putObject(cTID('Usng'), sTID('SaveForWeb'), desc22);
    executeAction(cTID('Expr'), desc21, DialogModes.NO);


You can save it as a scriptname.jsx file to Photoshop Folder/Presets/Scripts/, after restarting Photoshop you'll find it in File > Scripts > scriptname. You can then assign a shortcut to it from Edit > Keyboard Shortcuts menu.

  • @Basj you probably copied it wrong, all the brackets are in place. cTID() and sTID() are shortcuts for charIDToTypeID() and stringIDToTypeID() Apr 9, 2020 at 18:50
  • Thanks for your answer! Oops I didn't see the scrollbar :) What are these many similar lines desc22.putEnumerated(cTID('olEC'), cTID('STst'), cTID('ST00')); desc22.putEnumerated(cTID('olWH'), cTID('STwh'), cTID('WH01')); ... for? Are such lines really required to just simply save to JPG?
    – Basj
    Apr 9, 2020 at 18:55
  • @Basj please read the original answer to understand where this code comes from. You can save a JPG with one line of code, but it this will be Save As, not Save For Web: so this won't resize the result. You can rewrite this thing with shorter functions but it'll work differently and slower (clone document, resize it, save it, close the clone) Apr 9, 2020 at 19:02
  • 1
    this is Extendscript. It's like Javascript and Actionscript together. React uses the same acronym so sometimes there is confusion. JSX is based on quite old JS standards: no .filter(), .map(), etc (though those can be added via polyfill) Apr 9, 2020 at 19:08
  • 1
    You can find more information in PS JS references: adobe.com/devnet/photoshop/scripting.html Apr 9, 2020 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.