Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Is there a way with JSX to save text to a file?

Guest
Mar 08, 2013 Mar 08, 2013

I'm looking for a way to save JSX script-generated log entries to a text file, not just from Photoshop but also from InDesign and Illustrator as well. There are discussions elsewhere about using the DataObject class, but those discussions are from a few years ago, there is nothing about them (that I could find) in the CS6 documentation, and nothing comes up in EST's auto-complete. Any ideas? Thanks

TOPICS
Actions and scripting
6.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Mar 08, 2013 Mar 08, 2013

Something like this?

logInfo((new Date).toString());
logInfo("This is the first message");

logInfo("This is the second message");

function logInfo(Txt){
var file = new File(Folder.desktop + "/ScriptLog.txt");
file.open("e", "TEXT", "????");
file.seek(0,2);
$.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh';
file.writeln(Txt);
file.close();
};

Translate
Adobe
Valorous Hero ,
Mar 08, 2013 Mar 08, 2013

Something like this?

logInfo((new Date).toString());
logInfo("This is the first message");

logInfo("This is the second message");

function logInfo(Txt){
var file = new File(Folder.desktop + "/ScriptLog.txt");
file.open("e", "TEXT", "????");
file.seek(0,2);
$.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh';
file.writeln(Txt);
file.close();
};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 08, 2013 Mar 08, 2013

That would do it. Thanks so much. Out of curiosity, is that anywhere in Adobe docucmentation or is this pure Javascript?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 08, 2013 Mar 08, 2013

You can find this information in the Object Model Viewer under Help in ExtendScript Toolkit

Look at Core JavaScript Classes and select File

Hope it helps.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 08, 2013 Mar 08, 2013

It does. Thanks for the assist.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 09, 2013 Mar 09, 2013

There is documentation .pdf called JavaScript Tools Guide, also available under Help menu

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 22, 2019 Jan 22, 2019

right now this code saves the text file to the desktop.

what if we wanted to save it to:

C:\MyFolder\MyFiles

instead?

  1. logInfo((new Date).toString()); 
  2. logInfo("This is the first message"); 
  3. logInfo("This is the second message"); 
  4.   
  5. function logInfo(Txt){ 
  6. var file = new File(Folder.desktop + "/ScriptLog.txt"); 
  7. file.open("e", "TEXT", "????"); 
  8. file.seek(0,2); 
  9. $.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh'; 
  10. file.writeln(Txt); 
  11. file.close(); 
  12. };
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 22, 2019 Jan 22, 2019

If 'MyFolder' already exists, replace input of new File(), to "/c/MyFolder/ScriptLog.txt"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 13, 2022 Apr 13, 2022

What are the params ("e", "TEXT", "????") in file.open for?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2022 Apr 13, 2022
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 22, 2019 Jan 22, 2019

excellent, thank you Kukurykus!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines