Page 1 of 1

Render and shutdown

Posted: November 25th, 2004, 12:36 am
by Impudent1
As per discussions on the AE Listserv I have tossed together a basic render and shutdown script.

The script will render all queued objects in the render queue then it will shutdown.

This has not been tested on mac to please let me know how well it works ... utdown.jsx

Posted: November 25th, 2004, 3:11 am
by Disciple
Unfortunately in the current state it doesen't work on a mac. The error message says : "There is no defautl application specified to open the document "shutoff.bat"

So it seems that the part of your script that doesen't work is the creation of the sh file. I saw the bat file being created, even though I'm on a mac.

I looked into Applescript, and you could in fact have a simple applescript attached to your script called "Shutdown" and that would simply say something like

tell application "Finder" to shut down

But the Shell script is probably even better.

Why would you think it doesen't recognize the mac?


Posted: November 25th, 2004, 2:22 pm
by Guest
hmm so its locked to seeing it as a bat file. Does just using this part:

var exe_shutoff = new File("");"w");
exe_shutoff.writeln("shutdown -h now");

in a script work? or does it give the bat file message as well?

Posted: December 6th, 2004, 3:29 am
by Disciple
The error I get when I get rid of the PC part of the script is :

"After Effects error : Can't import file "":unsupported filetype or extension. (0-1)"

If I look at the desktop (place where the file was rendered), the .sh file was created. However if I double click on it to open it, it will invoke After Effects. This is probably because AE created the file, but I guess it is not the expected behavior, as the terminal sounds more like the correct app to open the file.

Why would AE want to import the script?


Posted: January 26th, 2005, 5:05 pm
by Paul Tuersley
The reason the script always writes a .bat file regardless of mac or pc, is the line towards the end of the script:
if (isMac = "false"){
which should be:
if (isMac == "false"){
i.e. the script is saying "make isMac equal false", when it should say "is isMac equal to false".

Also, while the line var isMac = "true"; assigns the string "true" to the variable, a more 'proper' way would be to write var isMac = true; which would assign the boolean true (i.e a variable that can only be true or false). It's a small point, but it means you can do things like:
var isThisTrue = true;
if (isThisTrue) {
i.e. if (true)
if (!(isThisTrue)) { i.e if (not (true))
What comes after the 'if' statement only proceeds if the argument between the brackets is true, and because a boolean variable is inherently either true or false, you don't need to write if (isThisTrue == true). Like I said, it's a small point.

As for why it still doesn't work even when the script is corrected, it appears to be trying to open the .sh file into AE, because that is the creator of the file. It doesn't seem that a .sh file is even a recognised extension, in fact I don't think you can create a file that will launch into the Terminal app (if this is what you're expecting it to open in). Unfortunately I don't have any experience in this whole area so I haven't been able to get any further in my investigations.

Paul T

Posted: January 27th, 2005, 10:43 am
by Disciple
Also, as I recently learned, you can't run a shutdown script without being logged in as root. I suppose you could use sudo, but you would probably need to identify, so it kind of beats the purpose of the script.


Posted: February 1st, 2005, 4:31 pm
by Paul Tuersley
Well it looks like I may have got Render & Shutdown working on the Mac, here's a new version of the script: ...

Instead of trying to get the script to write and launch an applescript (which may not be possible), I just got it to launch a shutdown applescript that I've included in the same folder as the .jsx script. Also, I added a line to the .jsx that closes the project without saving before it launches the shutdown script.

Paul T

Posted: February 3rd, 2005, 1:46 am
by Impudent1
ah very nice :)

I would assume then that anyone who wanted to setup things like the Gspot etc scripts for example on mac with mac applications would be able to use the same idea.

Posted: February 12th, 2005, 9:23 am
by Disciple
Paul, I noticed a catch with this script.

Yesterday I had setup a sort fo "master" render project for a bunch of other projects. I imported all the projects that had queued items and set the master render project to run (with render_and_shutdown).
One or more outputs modules had already been rendered in the "child" projects, and so I got the dialog box asking me if I wanted to overwrite previous modules.
As I said no, I think AE assumed it had done its job, and proceeded to shutdown and run the Applescript. This made me wait for the computer to shutdown, re-start, clean up my master render window, and relaunch the script.

Would there be a way for the script to understand the render hadn't actually taken place?


Posted: February 12th, 2005, 4:35 pm
by Impudent1
Hmm I would think you would just add into the check where it looks at RQitemStatus.QUEUED and add a test to see if any modules are marked as DONE then pull them out of the que list variable.

Re: Render & shut down using pure js

Posted: December 13th, 2009, 1:55 am
by zold
Paul Tuersley wrote:Instead of trying to get the script to write and launch an applescript (which may not be possible), I just got it to launch a shutdown applescript ...
Hey Paul.
In case you ever want to get this to work without having to use the external applescript app, you can do it this way:

Code: Select all

system.callSystem('osascript -e \'   tell application "Finder" to shut down   \'');

Re: Render and shutdown

Posted: December 13th, 2009, 5:43 pm
by zold
Incidentally, for the Mac-heads out there:
There is a particular advantage in using the "inline" method I presented above.
The only caveat to this is that I do not have Snow Leopard yet, so I have no idea if any of this functionality is broken in OS 10.6+.
If you run the osascript command without the "-e" option, specifying a script file, you cannot have user interaction (using, for example, AppleScript's "display dialog" command). But using the "-e" option allows this sort of thing, and this includes running this command using callSystem in an AE jsx.
So, you can do the following, which has two osascript calls in one callSystem line (go ahead and try it -- and if you have Snow Leopard, I would much appreciate feedback on whether or not this works in the latest OS:

Code: Select all

system.callSystem('osascript -e \'   activate application "Finder"\' ; osascript -e \'   tell application "Finder" to display dialog "Is this amazing?" buttons {"Slightly"} default button 1   \'');
Apologies for the long line. Spaces are added for readability. Of course, each callSystem/osascript command can be written in separate lines:

system.callSystem('osascript ... (first)
system.callSystem('osascript ... (second)

I just wanted to show what you could do with one line if you wanted.

This essentially makes the jsx/applescript possibilities limitless, although wrangling single quotes, double quotes and escaped quotes can be annoying.