Searching for a string in a .txt file from within Photoshop using js

Hi guys.

I’m using javascript within Photoshop to do some image processing.
As part of that image processing I have to read some information from a .txt file.

Does Photoshop have its own javascript methods for reading text files? I’m not having much luck with the documentation.

Regards,
Adam

ps. javascript and scripting in PS is completely new to me…

I think I can do it with new File (*.txt)
Too tired now and going home, will bash at it tomorrow

I recently wrote jsx to read a list of PSDs from text file then save them as tiffs.


#target photoshop
main();
function main(){
    //declare listFile variable, prompt to browse for text file
    var listFile = File.openDialog("Open List File","text(*.txt):*.txt;"); 
    //if no file selected, return
    if(listFile == null) return;
    //read the selected text file (listFile) to a string(listString)
    listFile.open('r') ; 
    var listString = listFile.read(); 
    listFile.close(); 
    //splitting at line breaks, convert into array of strings
    fileList = listString.split('
');
    //iterate array of strings (filenames), open & save as tiff
    for(var i=0; i<=fileList.length; i++){
        var theFile =new File(fileList[i]);
        app.open(theFile);
        saveAsTiff(theFile);
    }
};

function saveAsTiff(theFile){
    //tiff saving options here
}


once you read the file as a string, the JS function findstring() is probably what you want.

the Adobe documentation assumes you have some general JS competence.
when I first started java scripting, I found thewc3 siteinvaluable.
for Photoshop scripting , ps-scripts.com forumsare helpful.

In Mambo4’s example, since the text file’s list is already line-separated, you can just do a readln()


listFile.open('r');
while(!listFile.eof) {
  var theFileName = listFile.readln();
  DoStuffWith(theFileName);
}
fileList.close();

Thanks guys!

Where would one fine a list of all PS functions such as File.openDialog()?
neither the photoshop scripting reference or the ps js scripting reference contained this “File.openDialog” and a google search reveals little.

.open extendscript editor and goto help > object model viewer

Most awesome! thanks