2 Replies Latest reply on Oct 15, 2010 4:22 AM by derekfeldman

    Scripting a JPEG 'Save As'

    derekfeldman Level 1

      I'm doing some work for my company and I need to do what  is essentially stop-motion animation... I have my base .psd file, I move a layer  in it slightly, save it as a .jpeg, and repeat. And repeat, and repeat,  and repeat.


      However, it takes way too much time to go through the  'save as' dialogue, change the file name, and change the file type back  to jpeg every time.


      I don't know anything at all about  scripts (writing them OR using them), but from what I've read that's  where the solution to my problem lies... a script that will save a jpeg copy of my .psd file with a new name.


      In addition to that, it would be AWESOME if that could be set to a key or key combination... like I hit command + ~ and it runs the script.


      Can you guys help me?

        • 1. Re: Scripting a JPEG 'Save As'
          Paul Riggott Level 6

          NB: This is for Photoshop CS3 or better!

          Copy and paste the script into ExtendScript Toolkit, this gets installed with Photoshop

          This utility can be found in the relevant folder:-
          PC: C:\Program Files\Adobe\Adobe Utilities
          MAC: <hard drive>/Applications/Utilities/Adobe Utilities

          The script needs to be saved into:-
          PC: C:\Program Files\Adobe\Adobe Photoshop CS#\Presets\Scripts
          NB: Vista and Windows 7 you will have to save it elsewhere and copy it to this folder due to permissions.
          MAC: <hard drive>/Applications/Adobe Photoshop CS#/ Presets/Scripts

          If Photoshop was open, close and restart Photoshop so that it can pickup the new script.

          You can create an action to call the script
          Start recording a new action and from the action palette flyout select "Insert Menu Item" then File - Scripts and select the script.
          stop the recording.
          This action can be given a function key to run it.

          Another way is to create your own keyboard shortcut:
          Edit - Keyboard Shortcuts - File, go down till you see the script and assign your own shortcut.

          On first time use it will let you select the suffix start number.
          The files will be saved as OriginalFileName#0001.jpg OriginalFileName#0002.jpg etc..
          The files will be saved into the same folder as the original document.


          This first script is needed to reset the count back to none, when you want to work on the next document.

          app.eraseCustomOptions( 'a7ba92a0-d6f8-11df-937b-0800200c9a66');

          This is the main script...


          function main(){
          if(!documents.length) return;
          //Reset Custom Options.
          //app.eraseCustomOptions( 'a7ba92a0-d6f8-11df-937b-0800200c9a66' ); return;
          Count =0;
          var desc1 = app.getCustomOptions('a7ba92a0-d6f8-11df-937b-0800200c9a66');
          Count = desc1.getInteger(0);
          var win = new Window("dialog","File increment");
          win.pnl1 = win.add('panel');
          win.grp1 = win.pnl1.add('group');
          win.grp1.st1 = win.grp1.add('statictext',undefined,"File Suffix Number start...");
          win.grp1.et1 = win.grp1.add('edittext',undefined,"1");
          win.grp1.et1.onChanging = function() { 
            if (this.text.match(/[^\-\.\d]/)) { 
              this.text = this.text.replace(/[^\-\.\d]/g, ''); 
          win.grp10 = win.pnl1.add('group');
          win.grp10.process = win.grp10.add('button',undefined,'Okay');
          win.grp10.process.onClick = function(){
              Count = Number(win.grp1.et1.text);
          var Name = decodeURI(activeDocument.name).replace(/\.[^\.]+$/, '');
          var Path = decodeURI(activeDocument.path);
          var saveFile = File(Path + "/" + Name + "#" + zeroPad(Count,4) + ".jpg")
          SaveJPEG(saveFile, 8);
          var desc2 = new ActionDescriptor();
          desc2.putInteger(0, Count); 
          app.putCustomOptions('a7ba92a0-d6f8-11df-937b-0800200c9a66', desc2, true );
          }catch(e){alert(e + "\r@ Line " + e.line);}
          function SaveJPEG(saveFile, jpegQuality){
          var doc = activeDocument;
          if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;
          jpgSaveOptions = new JPEGSaveOptions();
          jpgSaveOptions.embedColorProfile = true;
          jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
          jpgSaveOptions.matte = MatteType.NONE;
          jpgSaveOptions.quality = jpegQuality; 
          activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
          function zeroPad(n, s) { 
          n = n.toString(); 
          while (n.length < s) n = '0' + n; 
          return n; 
          • 2. Re: Scripting a JPEG 'Save As'
            derekfeldman Level 1



            This was perfect, and incredibly helpful.


            Thank you x 97,000!