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

Applescript: file.open("r") returns empty in jsx

New Here ,
Oct 10, 2013 Oct 10, 2013

Hey guys,

i am having a bit of a scripting problem here. The big goal for me at the moment is creating a UI script to control aerender.

To achieve getting feedback from the terminal about when an aerender process is completed, i let the terminal trigger an applescript running a jsx inside after effects (since the terminal can't run a jsx inside after effects itself).

However, this particular script needs to eval the contents of a text file that is outputted during the render process (its just a log file put into a fixed location). No matter what i do: I can't get a proper response from the script. Here is what should happen when a render is done:

function RenderEnd () {

var report = new File ("Macintosh HD/Users/macname/generallog.txt");

report.open("r");

var reportstring = report.read();

report.close();

var reportendindex = reportstring.indexOf("Total Time Elapsed:");

var reportcloseindex = reportstring.indexOf("aerender version");

var reportendstring = reportstring.substring(reportendindex, [reportcloseindex]);

var regex = /Finished composition/gi, result, indices = [];

while ( (result = regex.exec(reportstring)) ) {

    indices.push(result.index);

}

var ItemStringArray = new Array ();

for(var i=0; i<indices.length; i++){

    ItemStringArray.push("Finished Item " + (i+1) + ": " + reportstring.substring(indices-32, [indices-2]));

    }

var AlertString = "Rendering done." + "\r" + reportendstring + "\r" + ItemStringArray.toString().replace(",","\r");

alert(AlertString);

}

RenderEnd ();

Running this script by itself properly returns an alert containing a message "Rendering done." plus additional info about the render time and item completion.

But whenever i have the following applescript triggering the above jsx script...

set scriptfile to (POSIX file ("/Applications/Adobe After Effects CS5.5/Scripts/AERenderEndTrigger.jsx"))

tell application "Adobe After Effects CS5.5"

  DoScriptFile scriptfile

end tell

...the line report.open("r") just returns empty.

Same goes when i place the jsx in the startup folder and just call the function RenderEnd () via applescript. It's as if the file open/read stuff does not work when using applescript.

Does anybody have an idea about this or knows the reason for why this obviously wrong behaviour happens? Maybe someone knows a different approach of how to get feedback from a completed aerender process back into a UI script.

TOPICS
Scripting
1.6K
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
Enthusiast ,
Oct 10, 2013 Oct 10, 2013

If you place in a check for the file existing, what do you get?

Try echoing or inspecting the value of report.exists like this, and maybe put in a check for that boolean in your code:

var report = new File ("Macintosh HD/Users/macname/generallog.txt");

if (report.exists) {

     report.open("r");

} else {

     $.writeln('Notice\n" + report.fsName + " does not exist.  Try setting your path again");

}

--Arie

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
New Here ,
Oct 15, 2013 Oct 15, 2013

Hey Arie,

thanks for your reply. It seems like applescript is not able to recognize the path within the jsx. When i check if the report exists as a file, i get a false return. The weird thing is: this false returns only when i run the script via applescript but when i run the script directly in extend script toolkit or after effects, everything works.

What can i do to make this work? Do i maybe have to escape characters within the path of var report = new File ("Macintosh HD/Users/macname/generallog.txt");?

It's weird because i don't see really what exactly the problem is for applescript to just tell AE to run the jsx instead of interpreting the jsx content.

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
New Here ,
Oct 15, 2013 Oct 15, 2013

Ok, i finally found the issue:

Applescript apparently does not recognize file paths beginning with a drive designation:

When i change the file path part of the report file from

var report = new File ("Macintosh HD/Users/macname/generallog.txt");

to simply

var report = new File ("/Users/macname/generallog.txt");

everything works as it should.

It's still a bit weird and i don't understand this. Maybe someone can explain this to me, please?

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
Enthusiast ,
Oct 15, 2013 Oct 15, 2013
LATEST

If you open up a terminal window, and type

ls /

You will see the root structure of your system.  All your "drives" are under the /Volumes drive.  You should try to navigate to that file in the terminal, then use the `pwd` command to see the true path to the file.  I'm not sure why AppleScript is able to reference the file when the path uses the drive name first.  In any case, you should take a look at the "Using File and Folder objects" in Adobe's Javascript Tools Guide (page 39) for more information about how ExtendScript deals with file paths.

Glad you got it working.

--Arie

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