I took a look at Photoshop CS5 Scripting Guide and Photoshop CS5 JavaScript Reference, but I couldn't find out a method to write text to a plain text file. Is there any way to do that?
I want to record the value of bounds
of each layer object in a document.
Any hint?
I found the docs lacking but came up with this as a method to create and write to a new file in CS6:
This works for me, saves text with the same name as original document, but with extension
txt
:I don't know how it works, photoshop scripting is a huge mess, I just kept mixing together a few scripts that I found until it worked.
Also, if anyone needs this, here is a script that also saves active document as
png
image:Here's what you need: It's pretty basic. It'll loop over the layers (no layersets!!) and save out the layer name and the layer bounds for each layer.
I have read the docs and combined best parts of psycho brm's and corrin_m's answer.
MY ANSWER ALSO CHECKS FOR ERRORS.
It is not necessary to delete file if it exists because opening with "w" will overwrite existing file it.
This is how I am using the function in my scripts
BTW I am keeping this in separate file called commom-code.jsx and I can include it with following line (single line comments are intentional).
File system access is documented in Adobe's JavaScript Tools Guide (PDF).
Download the PDF file and check out the "File System Access" section.