Skip to main content
September 10, 2014
Answered

Opening files one by one

  • September 10, 2014
  • 1 reply
  • 1560 views

Hi,

I'm trying to write a script to open file1 from folder Z, if file1 contains '10' in it's name then run action named '10', then open file2 from folder Z, if file2 contains '20' in it's name then run action '20' and so on for multiple files.

I've been searching for hours but can't find any help regarding opening a file, running action, and THEN opening the next file. All threads just regard opening multiple files at the same time.

Any kind of help would be very much appreciated.

Regards

This topic has been closed for replies.
Correct answer c.pfaffenbichler

Does this help?

#target photoshop

var theFolder = Folder.selectDialog ("select folder");

if (theFolder) {
	var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd)$/i);

	for (var m = 0; m < theFiles.length; m++) {
		var thisFile = app.open(File(theFiles[m]));

		if (thisFile.name.indexOf("10") != -1) {
			app.doAction(/*insert name of action*/, /*insert name of action set*/)
		}
	}
};

1 reply

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
September 11, 2014

Does this help?

#target photoshop

var theFolder = Folder.selectDialog ("select folder");

if (theFolder) {
	var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd)$/i);

	for (var m = 0; m < theFiles.length; m++) {
		var thisFile = app.open(File(theFiles[m]));

		if (thisFile.name.indexOf("10") != -1) {
			app.doAction(/*insert name of action*/, /*insert name of action set*/)
		}
	}
};
September 11, 2014

Wow. You're a hero - this worked perfectly. Just one more thing! I want to open these pdfs with certain settings so I'll add the below, but if you could just show me where to add the pdfOptions in the code.

var pdfOptions= new PDFOpenOptions(); 

 

pdfOpenOptions.antiAlias = true

pdfOpenOptions.mode = DocumentMode.RGB; 

pdfOpenOptions.bitsPerChannel = BitsPerChannelType.EIGHT; 

pdfOpenOptions.resolution = 300

pdfOpenOptions.cropPage = CropToType.TRIMBOX;

Thanks!

c.pfaffenbichler
Community Expert
Community Expert
September 12, 2014

var thePdf = app.open(/* the file*/, pdfOpenOptions);