Render and shutdown

Moderator: Impudent1

Post Reply
Impudent1
Posts: 57
Joined: June 12th, 2004, 6:40 pm

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

http://www.leapfrog-productions.com/Scr ... utdown.jsx
User avatar
Disciple
Posts: 137
Joined: June 5th, 2004, 8:05 am
Location: Los Angeles, CA
Contact:

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?

Alex
Guest

hmm so its locked to seeing it as a bat file. Does just using this part:

var exe_shutoff = new File("shutoff.sh");
exe_shutoff.open("w");
exe_shutoff.writeln("#!/bin/sh");
exe_shutoff.writeln("shutdown -h now");
exe_shutoff.writeln("rm shutoff.sh");
exe_shutoff.close();
exe_shutoff.execute();

in a script work? or does it give the bat file message as well?
User avatar
Disciple
Posts: 137
Joined: June 5th, 2004, 8:05 am
Location: Los Angeles, CA
Contact:

The error I get when I get rid of the PC part of the script is :

"After Effects error : Can't import file "shutoff.sh":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?

Alex
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

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)
or
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
User avatar
Disciple
Posts: 137
Joined: June 5th, 2004, 8:05 am
Location: Los Angeles, CA
Contact:

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.

Alex
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Well it looks like I may have got Render & Shutdown working on the Mac, here's a new version of the script:
http://www.paul.tuersley.btinternet.co. ... utdown.zip

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
Impudent1
Posts: 57
Joined: June 12th, 2004, 6:40 pm

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.
User avatar
Disciple
Posts: 137
Joined: June 5th, 2004, 8:05 am
Location: Los Angeles, CA
Contact:

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?

Alex
Impudent1
Posts: 57
Joined: June 12th, 2004, 6:40 pm

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.
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   \'');
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.

-CG
Post Reply