• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Incremental quicksaving

Community Beginner ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Hi there!

I am creating an action that has 3 basic functions;

  1. Save file with incremental number (ex: figuredrawing001.png)
  2. Close the file (without "are you sure" warning)
  3. Create new document figuredrawing

This is what I have so far

action.png

I am creating this to quickly save 30 second figure drawings and refresh my canvas.

I found an ancient script online that did roughly this but for some reason it would stop without error (or notifying me) at 008 for no apparent reason and came with a whole host of other issues. (Like when I tried it after closing photoshop it started overwriting 001 again for instance)

Is there a way to set this up quickly under a hotkey? For reference this is the script that I was working with.

// This script will save the active document to a folder with an incremental sufix
// Change the options below to match your needs
var saveFolder = new Folder( 'E:/Specialization/30seconddrawing' ); //don't put the ending "/" this is for mac folders windows is /c/foldername
var saveSufixStart = '_';
var saveSufixLength = 3;
saveOptions = new PNGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 8;
// End of user options
//==========================================
var saveExt = 'png';
function zeroPad ( num, digit ){
   var tmp = num.toString();
   while (tmp.length < digit) { tmp = "0" + tmp;}
   return tmp;
}
var docName = decodeURI ( activeDocument.name );
docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];
var saveName = docName[ 1 ]; // activeDocument name with out ext
var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix
if( files.length == 0 ) {  // no file with that name so start at one
   var saveNumber = 1;
}
if( files.length == 1 ) { // one file found, see if it has a sufix
   var fileName = decodeURI ( files[ 0 ].name );
   fileName = fileName.match( /(.*)(\.[^\.]+)/ ) ? fileName = fileName.match( /(.*)(\.[^\.]+)/ ) : fileName = [ fileName, fileName, undefined ];
   if( fileName[1].match( /_(\d{3})$/ ) == null ){
      var saveNumber = 1;// does not have sufix so set to one
   } else{// has sufix
      var saveNumber = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ) + 1; // strip the ext and get the sufix , convert to number and add 1
   }
}
if( files.length > 1 ){
   files.sort();
   var fileName = decodeURI ( files[ files.length -1 ].name );
   fileName = fileName.match( /(.*)(\.[^\.]+)/ ) ? fileName = fileName.match( /(.*)(\.[^\.]+)/ ) : fileName = [ fileName, fileName, undefined ];
   var saveNumber = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ) + 1; // strip the ext and get the sufix , convert to number and add 1
}
var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );
activeDocument.saveAs( saveFile, saveOptions ,true ,Extension.LOWERCASE);
TOPICS
Actions and scripting

Views

3.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 26, 2018 Jan 26, 2018

if (displayDialogs = DialogModes.NO, (d = documents).length) {

     function dateMod(v) {return new Date(File(v).modified).getTime()}

     f = File(String(F = (p = Folder('/e/Specialization/30seconddrawing'))

     .getFiles(/\.png$/i).sort(function(a, b) {return dateMod(a) - dateMod(b)})

     .pop()).replace(/(\d+)(?=\.png$)/i, function() {return ++arguments[1]}))

     function sve(v){d[0].saveAs(v,png),d[0].close()}

     (png = new PNGSaveOptions()).compression = 9

     w = d[0].width, h = d[0].height

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

To me it looks like you change:

saveOptions = new JPEGSaveOptions();

to

saveOptions = new PNGSaveOptions();

You now need to set the png options you want to use not the jpeg options in the variable saveOptions

PNGSaveOptions

Options for saving a document in PNG format using the Document.saveAs() method.

Properties

Property Value type What it is

compression number [0..9] Read-write. The compression value (default: 0).

interlaced boolean Read-write. True to interlace rows (default: false).

typename string Read-only. The class name of the referenced PNGSaveOptions object.

It also looks like the your Action will always close the incremented document and create a new document in Photoshop named 30secdrawing. If your action is player more that once the incremental script will overwrite increment 1 if the gets file list and sort and add 1 does not work.  If there are files in the output folder with the names 30secdrawing+suffix=.png  a files list array should be returned.  I do not understand regular expressions.  Your 30 may be messing that up you may want to try changing  the filename to ThirtySecDrawing there are many regular expression used in the script  to process filename

var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix

if( files.length > 1 ){
   files.sort();
   var fileName = decodeURI ( files[ files.length -1 ].name );

   fileName = fileName.match( /(.*)(\.[^\.]+)/ ) ? fileName = fileName.match( /(.*)(\.[^\.]+)/ ) : fileName = [ fileName, fileName, undefined ];

/////////////////////////////////////////////////////////////////////////////////////////////

   var saveNumber = parseInt( fileName[ 1 ].match( /_(\d{3})$/ )[1] ) + 1; // strip the ext and get the sufix , convert to number and add 1

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Fix the png save options.

You can set a Fn key or FN key + Shift or Ctrl to play your action Alt + Click on the Action Name in the Action Set.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

You can forget about that lame script I come with something more consitent you can use smoothly even reopening Photoshop. Just tell me what you would like to be changed in this script if that does not fit you completely and I'll do it:

function mod(v) {return new Date(File(v).modified).getTime()}

if (displayDialogs = DialogModes.NO, (d = documents).length) {

     f=File(String(F=(p=Folder('~/desktop/I')).getFiles(/\.png$/i)

     .sort(function(a, b) {return mod(a) - mod(b)}).pop()).replace

     (/(\d+)(?=\.png$)/i, function() {return ++arguments[1]}));

     (png = new PNGSaveOptions()).compression = 9

     function sve(v) {d[0].saveAs(v, png), d[0].close()}

     sve(+!!F ? f : File(p + '/0.png')), d.add()

}

else alert('Open / create at least one document!')

Don't forget to save it in your Photoshop > Presets / Scripts folder. After you reopen Photoshop you can bind it to action or do something I prefer personaly so make shortcut (from Edit / Keyboard Shortcuts), however actions have higher priority...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

From his action after the save as png he want the document closed and a new similar empty document opened with the same orginal document name. I can not tell if  it should have a transparent layer 0 or have a color. All should saved into his  E:/Specialization/30seconddrawing not on his desktop I

Its great that your scripts are consitent and well written but for those new to scripting or someone like me that does not know javascript I only hack on them.  Your advance coding style is very hard to read.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Yes I know. But I would like to wait for him to tell me it clearly as these things are enough easy he can change script himself, and there is another thing that may be not so important. Last 4 days I wrote few scripts for people who came here to ask for help in solving their problems. Where they are now? 😛
I wrote what they wanted and they even didn't come to see anyone answered anything ha ha. There are at least 4 scripts from last days they do what they wanted but it seems they do not care about, and want to do everything manually despite they stated 🙂
Well if he'll answer then I update script instead of loosing time for potentially another 'ghost' person 😄

 

Sorry for hard coding. I understand it. It's just my specific style. I never knew that happen some day, but I worked out that, or rather that came to me naturally. If there is something that someone can't get, I'm willing to explain every single line 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Hey there!

Thanks so much for the quick help. It does roughly what I want it to do. I love that it still numbers accurately even after closing photoshop.

What can I change to make the new document that opens after saving and closing the original have the same size and general settings?

I see    sve(+!!F ? f : File(p + '/0.png')), d.add() 


Something for the document name like: var p = app.activeDocument

could work?

Right now this:

turns into this:

It would be great if resolution and current filename and document settings was retained so I can for instance have a thirtysecond drawing folder with

figuredrawing1.png

figuredrawing2.png

figuredrawing3.png

...

And then the next day create a document with a different size called
facialexpression.png

save to the same folder with

facialexpression1.png

facialexpression2.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

if (displayDialogs = DialogModes.NO, (d = documents).length) {

     function dateMod(v) {return new Date(File(v).modified).getTime()}

     f = File(String(F = (p = Folder('/e/Specialization/30seconddrawing'))

     .getFiles(/\.png$/i).sort(function(a, b) {return dateMod(a) - dateMod(b)})

     .pop()).replace(/(\d+)(?=\.png$)/i, function() {return ++arguments[1]}))

     function sve(v){d[0].saveAs(v,png),d[0].close()}

     (png = new PNGSaveOptions()).compression = 9

     w = d[0].width, h = d[0].height, r = d[0].resolution

     n = d[0].name, sve(+!!F ? f : File(p + '/' + n + '1.png'))

     d.add(w, h, r, n, NewDocumentMode.RGB, DocumentFill.

     WHITE, 1, BitsPerChannelType.EIGHT, 'sRGB IEC61966-2.1')

}

else alert('Open / create at least one document!')

Now it will always use E:\Specialistaion\30seconddrawing path to save your files (name you used creating file + increasing number suffix), while counting now is going to start not from 0, but 1. You also get width, height, resolution and name that will be applied to new document creation, while name additionally for savings. As to rest document settings they will be always the same (so even when you opened document with other, all next ones will keep properties written from script). They are rgb mode, white filling, square pixels, eight bits per channel and some sRGB color profile. If you need others tell me and I replace them, however I try other method to read all documents settings that is called Antion Manager, hard one.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Good job...

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Thanks for this.

It wasn't exactly what I was looking for but you did provide enough information for me to modify this for my purpose which was to save jpg with an incermental file number.

I added this code to pad the number:

Number.prototype.pad = function(size) {
    var s = String(this);
    while (s.length < (size || 2)) {s = "0" + s;}
    return s;
}

and modified the function to return a zero  padded number like this:

f = File(String(F = (p = Folder(fldr))
     .getFiles(/\.jpg$/i).sort(function(a, b) {return dateMod(a) - dateMod(b)})
     .pop()).replace(/(\d+)(?=\.jpg$)/i, function() {return (++arguments[1]).pad(3);}))

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Pinging @Kukurykus (even if the request is old, it might still help someone)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

I too find it disappointing that many users do not acknowledge that the have read the replies or that they no longer have a problem.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

That script made by Kukurykus is fantastic.

 

It does three things that I need:

1. It saves file to specific folder without showing save dialog

2. If I run script again, it doesn't overwrite the previously saved file, instead it continues file name numbering (Untitled-11.png, Untitled-12.png and so on.)

3. If I restart Photoshop, create new file and PS generates the default name Untitled-1 for it, I can still use the script to save file without overwriting previous files.

 

I wanted to keep saved file open, so I changed close() to close(0).

 

I wanted similar script to save JPEG, GIF and TIFF files too. I edited the script and changed every "PNG" to "JPEG". Script saved JPEG files to right folder, but it always overwrited the previously saved file. I want to keep previous versions and continue file numbering.

 

Then I changed every "PNG" to "GIF". That script didn't save anything anywhere.

 

Can anyone help me? I'm a newbie in scripting. I want to save JPEG, GIF and TIFF same way like the original script saves PNG's.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

LATEST

Find methods for other file formats instead of JPG options in Photoshop Javascript Reference

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines