Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions applescript: executing a jsx in after effects

  • applescript: executing a jsx in after effects

    Posted by Andy Kreutzberg on October 9, 2013 at 2:17 pm

    Hey again,

    it seems i am not the only person having trouble getting scripts to run via applescript, so i thought i would present my case here. I have the following script that i want to run after the aerender application has been executed from the terminal and finished rendering:

    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

    This is basically compiling a list of date information from a log file for each finished item in the render queue after they have been rendered by aerender and notifies the user with that info that aerender is completed.

    This script is being executed in the following way:

    First, a script initiates the aerender process by passing commands to the terminal. One command at the very end triggers the above notification script by running an applescript called "TerminalReply.scpt":

    system.callSystem('osascript -e 'tell application "Terminal" to do script ["command /Applications/Adobe\\ After\\ Effects\\ CS5.5/aerender -project /Users/ikono25/projects/code/RenderReportTest_2.aep> generallog.txt;osascript /Applications/Adobe\\ After\\ Effects\\ CS5.5/Scripts/TerminalReply.scpt"]'');

    The code within this TerminalReply.scpt is the following:

    set scriptfile to (POSIX file ("/Applications/Adobe After Effects CS5.5/Scripts/TerminalAntwort.jsx"))
    tell application "Adobe After Effects CS5.5"
    DoScriptFile scriptfile
    end tell

    The script is being executed in after effects, but sadly in the wrong way. Let me explain:

    The notification from the first script should contain information about the items rendered and the total render time. When i run the script manually from the toolkit, i get the correct infos alerted. When i run it over the terminal>applescript way, it only alerts "rendering done." without any additional info. The variables used to create the "AlertString" are empty when running the script via applescript.

    I have tried some other solutions but none seem to work. The problem seems to be related to applescripts way of reading the contents or passing the jsx to after effects.

    I really need some help here as to understand what the problems are because when automating aerender, there is no way of avoiding applescript and terminal as far as i can tell.

    Andy Kreutzberg replied 12 years, 7 months ago 2 Members · 6 Replies
  • 6 Replies
  • Andy Kreutzberg

    October 9, 2013 at 3:34 pm

    I isolated the problem: When running a jsx script via applescript in after effects, the file.open() method does not work. It just returns an empty content. I found this out when i tried to call the notification script above as a nested script from another one executed by applescript.

    When i run the script containing the nested notification script manually, everything works. However, executing the script with the nested script via applescript does just nothing.

    Is there a solution for this problem? And if not, how would it be possible to have any script being executed after the aerender process is complete?

  • Mitch Mann

    October 9, 2013 at 7:55 pm

    I was researching this a while back, but abandoned it because I’m switching back to Windows soon.

    I successfully did it the other way around: I got a jsx to run an applescript, cleverly having applescript trigger keyboard shortcuts in AE that are not available to scripting. But I never tried having an applescript run a jsx.

    As far as your issue with an externally triggered jsx not being able to use file.open(), I have a thought. Here goes…

    When you have multiple script UI scripts running in AE at the same time, one of the scripts can use the other script’s functions. So I wonder if you could launch a script UI in AE (launch it yourself manually from inside AE) that has a function which uses your file.open(). Then have the externally launched jsx use that script’s function to do the file.open() work. And if your applescript needs to open AE in the first place, perhaps you could have AE autoexecute the script UI with the function in it also.

    Hope some of that makes some kind of sense! Don’t know if it would work, but its worth a try.

    Cheers,
    Mitch

    PS: And in the “Mam, is your computer plugged into the wall?” category, we’re all assuming that you checked the preferences box for Also Scripts to Write Files. (-:

  • Andy Kreutzberg

    October 10, 2013 at 11:32 am

    Yes, allow scripts to write files thing is active. It’s interesting what you say about the UI Script, because the whole idea i am pursuing is in fact a UI script to control the aerender. So in the end, that particular UI Script should just have functions that an external script is calling via applescript.

    In the end, i would probably not have all these problems if the terminal was just able to make AE execute a script, but unfortunately, only the windows equivalent is able to do that while on mac you need the stupid applescript detour.

    Thanks a lot, Mitch. Your idea really opens additional possibilities. I will test it out. But maybe if somebody knows a radically different approach of telling an AE script that a process of aerender is done, feel free to chime in 😉

  • Andy Kreutzberg

    October 10, 2013 at 12:48 pm

    So here is what i tried now:

    I placed the script with the File to evaluate in the startup folder and put the open file, eval file stuff within a function called RenderEnd (); I then tried to call this function via applescript. Guess what? It’s the same again. The File operations are still being ignored completely even though the function is executed.

    Now how come nobody ever ran into this issue? Apparently, it is not possible to have any sort of file handling operations within a jsx executed by applescript. That stuff will just get ignored as if it does not exist or something. Very strange.

  • Mitch Mann

    October 12, 2013 at 4:52 am

    Andy- this is certainly important stuff that is relevant to many kinds of AE automation. Good to have it here on the forum for others to digest and figure out. Don’t know if it’s a security thing or a bug.

    I know that AppleScript can execute keyboard shortcuts in AE. I wonder if you could get a keyboard shortcut to run your script seemingly internally in AE by triggering a keyboard command.

    Curious what master Dan thinks about this.

    Mitch

  • Andy Kreutzberg

    October 15, 2013 at 3:33 pm

    Hey again,

    a little update on this as i found a possible solution: The source of evil is the path of

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

    Changing this to

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

    Makes the generallog.txt file work when the applescript executes the jsx file in ae. It’s still weird though because this means that as a result of running a jsx in after effects via applescript, there is a difference in how file paths within a jsx are being handled compared to when you just run a script without applescript.

    I am a bit confused, but thankfully this fix is rather simple even though i do not get the reason for this 😉

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy