Looking for help with text layer incrementing and saving as jpg

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

FiannaTiger
Posts: 2
Joined: Sun Apr 15, 2018 4:28 pm

Looking for help with text layer incrementing and saving as jpg

Post by FiannaTiger »

So I am trying to take a PSD that I set up with just one text layer and append a number to the text layer and then save it as a JPG. The text layer will have text in it with a space at the end. I’ve to find something like this but currently haven’t been able to find something that will append the number and then save it as that number. Example: text layer would be “Test video “ the PsD file name would be TV.PSD. Want to to creat “Test video 1” and TV1.jpg and then do that until “Test video 100” saved as TV100.jpg all in the original folder that TV is set into.

So I have put together this and wondering if this will work (can't test it till this evening)

Code: Select all

    var OrigionalText = app.activeDocument.layers[1].textItem.contents;
var Name = decodeURI(activeDocument.name).replace(/\.[^\.]+$/, '');
var Path = decodeURI(activeDocument.path);

for(var i = 0; i<101 ; i++){
app.activeDocument.layers[1].textItem.contents = app.activeDocument.layers[1].textItem.contents + i;
var saveFile = File(Path + "/" + Name + i + ".jpg")
SaveJPEG(saveFile, 8);
app.activeDocument.layers[1].textItem.contents = OrigionalText;
}

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);
}
FiannaTiger
Posts: 2
Joined: Sun Apr 15, 2018 4:28 pm

Re: Looking for help with text layer incrementing and saving as jpg

Post by FiannaTiger »

So the code worked pretty well except the layer was 0 not 1 for the text field and I adjusted the loop to start at 1 instead of 0. One last thing is the save file didn't have a space after the name which was just fine in my book.
wasfiwasfi
Posts: 45
Joined: Fri Nov 04, 2016 8:29 am

Re: Looking for help with text layer incrementing and saving as jpg

Post by wasfiwasfi »

Code: Select all

   var OrigionalText = app.activeDocument.layers[0].textItem.contents;
var Name = decodeURI(activeDocument.name).replace(/\.[^\.]+$/, '');
var Path = decodeURI(activeDocument.path);
var docName = activeDocument.name;
for(var i = 1; i<101 ; i++){
app.activeDocument.layers[0].textItem.contents = app.activeDocument.layers[0].textItem.contents +' ' +parseInt(i).toString();
var saveFile = new File(Path + "/" + Name + i + ".jpg")
SaveJPEG(saveFile, 8);
var idslct = charIDToTypeID( "slct" );
var desc3909 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref650 = new ActionReference();
var idSnpS = charIDToTypeID( "SnpS" );
ref650.putName( idSnpS, docName );
desc3909.putReference( idnull, ref650 );
executeAction( idslct, desc3909, DialogModes.NO );
}

alert('Do you need something else !!')
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);
}
wasfiwasfi
Posts: 45
Joined: Fri Nov 04, 2016 8:29 am

Re: Looking for help with text layer incrementing and saving as jpg

Post by wasfiwasfi »

here is the psd template, just to make sure you don't use a different psd structure...
otherwise you will need to point the script to the correct text layer index.
Sorry for being late to reply, i was very busy
Cheers,
Wasfi
Attachments
test.zip
(44.24 KiB) Downloaded 422 times