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

Quick Save as Versions with Script?

Community Beginner ,
Nov 10, 2013 Nov 10, 2013

Copy link to clipboard

Copied

I'm looking to modify a script I found online but unfortunately I don't know enough Javascript to figure it out.

Here's the original code from this blog post:

#target photoshop;

if (app.documents.length > 0) {

var thedoc = app.activeDocument;

  var docName = thedoc.name;

if (docName.indexOf(".") != -1) {

  var basename = docName.match(/(.*)\.[^\.]+$/)[1]

} else {

  var basename = docName

}

  //getting the location, if unsaved save to desktop;

try {

  var docPath = thedoc.path

} catch (e) {

  var docPath = "~/Desktop"

}

var jpegOptions = new JPEGSaveOptions();

jpegOptions.quality = 9;

jpegOptions.embedColorProfile = true;

jpegOptions.matte = MatteType.NONE;

var filename = docPath + '/' + basename + "-" + getTime() + '.jpg';

  thedoc.saveAs((new File(filename)), jpegOptions, true);

};

function getTime(){

var currentTime = new Date();

  //Make single-digit mins show up as 6:01 and not 6:1

var minutes = currentTime.getMinutes();

if (minutes < 10) {

  minutes = "0" + minutes;

}

  var timeStamp = currentTime.getFullYear() + "-"

     + (currentTime.getMonth() + 1) + "-"

     + currentTime.getDate() + "-"

     + currentTime.getHours() + "."

     + minutes + "."

     + currentTime.getSeconds() + "."

     + currentTime.getMilliseconds();

return timeStamp;

}

What I'm trying to do is instead of saving with a timestamp, I'd rather have the script automatically detect the most recent version (eg: MyPicture_04.jpg) and save as the next logical increment (eg: MyPicture_05.jpg)

Anyone know how I'd be able to go about scripting that?

Thanks!

TOPICS
Actions and scripting

Views

829

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
Adobe
Community Expert ,
Nov 10, 2013 Nov 10, 2013

Copy link to clipboard

Copied

try this:

#target photoshop

if (app.documents.length > 0) {

var thedoc = app.activeDocument;

   

  var docName = thedoc.name;

if (docName.indexOf(".") != -1) {

  var basename = docName.match(/(.*)\.[^\.]+$/)[1]

} else {

  var basename = docName

}

  var baseArray = basename.split("_")

  var imgNumStr = baseArray[baseArray.length-1]

  var replaceNum = Number (imgNumStr) + 1000000001

  var replaceStr = replaceNum.toString().substr (replaceNum.toString().length-imgNumStr.toString().length, imgNumStr.toString().length)

 

  var nameBeg = basename.substr(0,basename.length-replaceStr.length)

 

  if(Number (replaceStr)==0)

  {replaceStr = replaceNum.toString().substr (replaceNum.toString().length-imgNumStr.toString().length-1, imgNumStr.toString().length+1)}

  //getting the location, if unsaved save to desktop;

try {

  var docPath = thedoc.path

} catch (e) {

  var docPath = "~/Desktop"

}

var jpegOptions = new JPEGSaveOptions();

jpegOptions.quality = 9;

jpegOptions.embedColorProfile = true;

jpegOptions.matte = MatteType.NONE;

var filename = docPath + '/' + nameBeg + replaceStr +  '.jpg';

  thedoc.saveAs((new File(filename)), jpegOptions, true);

};

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 ,
Nov 10, 2013 Nov 10, 2013

Copy link to clipboard

Copied

Hey, thanks for your help.

When I loaded your script it would revoke some of the naming of my original file, but with some tinkering I got it to work, but there are still some problems. One is it only saves one copy and then it'll just overwrite it...and the other is that when I'm creating the first save, my file comes out as 3LINE_V2_02a_NaN.jpg (bold is the part the script creates, the rest is my filename) and then after that it'll just overwrite it. Here's the script I have atm:

--------------------------------------------------------------------------

#target photoshop;

if (app.documents.length > 0) {

var thedoc = app.activeDocument;

  var docName = thedoc.name;

if (docName.indexOf(".") != -1) {

  var basename = docName.match(/(.*)\.[^\.]+$/)[1]

} else {

  var basename = docName

}

  if (docName.indexOf(".") != -1) {

   var basename = docName.match(/(.*)\.[^\.]+$/)[1]

  } else {

   var basename = docName

  }

  var baseArray = basename.split("_")

  var imgNumStr = baseArray[baseArray.length-1]

  var replaceNum = Number (imgNumStr) + 1000000001

  var replaceStr = replaceNum.toString().substr (replaceNum.toString().length-imgNumStr.toString().length, imgNumStr.toString().length)

  var nameBeg = basename.substr(0,basename.length-replaceStr.length)

  if(Number (replaceStr)==0)

  {replaceStr = replaceNum.toString().substr (replaceNum.toString().length-imgNumStr.toString().length-1, imgNumStr.toString().length+1)}

  //getting the location, if unsaved save to desktop;

try {

  var docPath = thedoc.path

} catch (e) {

  var docPath = "~/Desktop"

}

var jpegOptions = new JPEGSaveOptions();

jpegOptions.quality = 10;

jpegOptions.embedColorProfile = true;

jpegOptions.matte = MatteType.NONE;

var filename = docPath + '/' + basename + "_" + replaceStr + '.jpg';

  thedoc.saveAs((new File(filename)), jpegOptions, true);

};

function getTime(){

var currentTime = new Date();

  //Make single-digit mins show up as 6:01 and not 6:1

var minutes = currentTime.getMinutes();

if (minutes < 10) {

  minutes = "0" + minutes;

}

  //Make single-digit hours show up as 06:01 and not 6:1

var hours = currentTime.getHours();

if (hours < 10) {

  hours = "0" + hours;

}

  var timeStamp = currentTime.getFullYear() + "_"

     + (currentTime.getMonth() + 1) + "_"

     + currentTime.getDate() + "_"

     + currentTime.getHours() + "_"

     + minutes + "_"

     + currentTime.getSeconds()

return timeStamp;

}

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 ,
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

LATEST

learn quick functions in Photoshop http://skillonpage.com/quick-functions-photoshop/

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