我一直无法找到任何与我的明显小众案例类似的东西。
我有很多 .png 文件,所有这些文件上都有矩形或正方形的透明度。我创建了一个脚本来查找边界,并将此信息写入文本文件。
目前的行为是脚本为每个图像创建一个文本文件,并将我需要的信息写入该文件。
目前代码如下:
//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();
.
我已经开始研究它了,但是没能成功附加到一个文件:
//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();
.
附加到单个文件将使创建文件后的工作变得更加容易。任何帮助将不胜感激。
最佳答案
您目前正在“写入”文件,而不是“追加”。
- //open() 方法
- fileExample.open("w");//写
- fileExample.open("e");//编辑
- fileExample.open("a");//追加
你应该能够改变
Loginfo.open("w", "TEXT");
到
Loginfo.open("a", "TEXT");
关于javascript - 使用 Photoshop 脚本 (.jsx) 附加到现有文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18240838/