Append to an existing text file using Photoshop Scripting ( .jsx )
javascript, jsx, photoshop
Solution
You're currently "writing" to the file, not "appending".
- // open() method
- fileExample.open("w"); // write
- fileExample.open("e"); // edit
- fileExample.open("a"); // append
You should be able to change
Loginfo.open("w", "TEXT");
to
Loginfo.open("a", "TEXT");
Problem
I've been unable to find anything similar to my apparently niche case. I have many .png files, all of which have a rectangular or square transparency on them. I have created a script which finds the bounds, and writes this info to a text file. Currently the behaviour is that the script creates a single text file for each image, and writes the info I need to that file. The code is currently as follows: ``` //Create logfile FOLDER on the desktop var LogFolder = new Folder(Folder.desktop + "/LogFiles/"); if(!LogFolder.exists) LogFolder.create(); //NOTE TO SELF: Would be optimal if appended to single log file //Create new LOGFILE in the folder using image name var Loginfo = new File(Folder.desktop + "/LogFiles/" + activeDocument.name.replace(/\.[^\.]+$/, '') + ".txt"); Loginfo.open("w", "TEXT"); //Write the info to the file Loginfo.write(activeDocument.name.replace(/\.[^\.]+$/, '') + ", " + selectionWidth + ", " + selectionHeight + ", " + selectionTopLeftXOffset + ", " + selectionTopLeftYOffset); //Close the log Loginfo.close(); ``` . I've started working at it, but have had no luck making it append to a single file: ``` //Create logfile FOLDER on the desktop var LogFolder = new Folder(Folder.desktop + "/LogFiles/"); if(!LogFolder.exists) LogFolder.create(); //Append to LOGFILE var Loginfo = new File(Folder.desktop + "/LogFiles/" + "coords.txt"); Loginfo.open("w", "TEXT"); //Write the info to the file Loginfo.write(activeDocument.name.replace(/\.[^\.]+$/, '') + ", " + selectionWidth + ", " + selectionHeight + ", " + selectionTopLeftXOffset + ", " + selectionTopLeftYOffset + "\r"); //Close the log Loginfo.close(); ``` . Appending to a single file would make the work that follows the creation of the file significantly easier. Any help would be greatly appreciated.