Skip to main content
AG_Ps_100
Inspiring
April 21, 2019
Answered

Create and update a log file

  • April 21, 2019
  • 2 replies
  • 4390 views

Hello everyone,

I want to create a log file and later open it in Excel. I believe a txt file will be just fine. (maybe if it's easy to differ values in the log by tab or comma or something)

I want to know how to:

1. create it

2. update it

I would like to be able to write error logs, and other logs as well (for example - if a document is 1000x1000px then write to log: document name + path)

Thank you in advance

This topic has been closed for replies.
Correct answer SuperMerlin

SuperMerlin​ can you please share the code to:

see if the file is closed

     if not then close it

          if prompted to save the file (changes where made) then save the file

r-bin​ csv file was created, let's say I opened it in Excel


There is no easy way to close the file if it is opened by an external program, it would depend on the operating system on how you could manage it again calling an external program.

The easy way would be to tell the user to close the program if the script could not open the csv file...

#target photoshop 

main();

function main(){

if(!documents.length) return;

var doc = activeDocument; 

var a,b,c,d =""; 

var log = File(Folder.desktop + "/LogFile.csv"); 

var result = log.open("a"); 

if(!result) {

    alert("you must close " + log.name + " before running this script");

    return;

    }

a=decodeURI(doc.name).replace(/\.[^\.]+$/, '');

b=decodeURI(doc.path.fsName); 

c=doc.info.keywords.toString().replace(/,/g,";"); 

d=doc.info.caption; 

log.writeln(a +","+b +"," + c + "," +d); 

log.close(); 

};

2 replies

AG_Ps_100
AG_Ps_100Author
Inspiring
June 5, 2019

Wanted to ask what about writing an error to log and continue?

I believe it's possible, whenever you encounter an error, for example: I have tried to open a psd file and got the error message:

"Could not complete your request because an unexpected end-of-file was encountered", i want to be able to write to log the error quote (if possible) and continue to the next file.

c.pfaffenbichler
Community Expert
Community Expert
April 21, 2019

Is the log created via

Photoshop > Preferences > History Log

not sufficient?

What exactly do you need to record?

AG_Ps_100
AG_Ps_100Author
Inspiring
April 21, 2019

I have a script that opens every TIF file in a folder (sub-folders included), i want in the log to see in a separate row for each file:

1. file name

2. path

3. metadata (tags, description)

I know the lines for each of the things i want, I just don't know the lines to create/update to log.

SuperMerlin
Inspiring
April 22, 2019

var doc = activeDocument;

var a,b,c,d ="";

a=decodeURI(doc.name);

b=decodeURI(doc.path.fsName);

c=doc.info.keywords.toString().replace(/,/g,";");

d=doc.info.caption;

$.writeln(a +","+b +"," + c + "," +d);