Skip to main content
Participant
September 15, 2017
Answered

script/action to append filename to text document

  • September 15, 2017
  • 4 replies
  • 3792 views

Is it possible to create an action or script that will append the filename of the currently open PSD to a text file? Or if that's not possible, can a script copy the filename to the clipboard?

Thanks!

This topic has been closed for replies.
Correct answer Tom Winkelmann

#target photoshop

var fname = activeDocument.name;

var a = new File("\\c\\filenames.txt");

a.open('a');
a.write(fname + "\n");
a.close();

4 replies

Participant
March 5, 2020

Is this javascript or something else?

Kukurykus
Legend
March 6, 2020

Specifically ExtendScript.

JJMack
Community Expert
Community Expert
September 16, 2017

Note that code would write the document name into the filenames.txt file. It may or may not have and extension and the document may not have been saved so no file may exists and there is no path written

JJMack
Tom Winkelmann
Tom WinkelmannCorrect answer
Inspiring
September 16, 2017

#target photoshop

var fname = activeDocument.name;

var a = new File("\\c\\filenames.txt");

a.open('a');
a.write(fname + "\n");
a.close();

Participant
September 17, 2017

This is great. Just tried it, and it worked exactly as I need. Thank you so much!

FWIW, I modified the path for the file creation to work on Mac. In case it's useful to anyone else:

#target photoshop 

var fname = activeDocument.name; 

var a = new File("/Users/USERNAME/Documents/filenames.txt"); 

a.open('a'); 

a.write(fname + "\n"); 

a.close(); 

JJMack
Community Expert
Community Expert
September 16, 2017

Scripts can open file for write and write to them.  There are many scripts that create text documents like html and xml files etc. JavaScript for sure supports your OS file systems.  If the current active document has been save there is a file backing it and a script can retrieve its path and file name. Actions can not use logic or creat text files. Actions can have script steps.

JJMack