is there a way to programmatically run a shell command after a render has completed in Adobe After effects?
You can execute a command line with the sysmte.callSystem(cmdLineToExecute)
function. Go see the After Effects Scripting Guide page 180 section System callSystem() method.
Here is an exemple whith a echo
command : (callSystem
returns the command line return's) :
var commandOutput = system.callSystem("cmd.exe /c echo hi ");
alert(commandOutput);
This will output
hi
What is after /c
is the command to execute in the cmd.
A more complex exemple from the scripting guide which get the system time :
var timeStr = system.callSystem("cmd.exe /c \"time /t\"");
alert("Current time is " + timeStr);
This will output
Curent time is 11:28
Now if you are looking to open a command line in another window, you have to set the cmdLineToExecute
as if you were in a command line.
On windows, if you want to open a command line in another window, you have to do this :
start cmd.exe
So if you want to do it from After
system.callSystem("cmd.exe /c start cmd.exe ");
This is a mix with @fabiantheblind's answer.
// Create a comp with a solid
var comp = app.project.items.addComp('test', 100, 100, 1, 1, 12);
comp.layers.addSolid([0.5, 0.5, 0.5], 'solid', 100, 100, 1, 1);
// Add the comp to the render queue
var rq_item = app.project.renderQueue.items.add(comp);
rq_item.outputModule(1).file = File('~/Desktop/out.mov');
rq_item.render = true;
// Set a function which will be called every frame when the comp will be rendering
// A boolean to be sure that the function called at the end is called once
var called = false;
rq_item.onStatusChanged = function() {
while (rq_item.status === RQItemStatus.RENDERING) {
// Is rendering...
$.writeln('Rendering');
}
// When the render is finished
if (!called && rq_item.status === RQItemStatus.DONE) {
called = true;
system.callSystem("cmd.exe /c start cmd.exe ");
}
};
// Launch the render
app.project.renderQueue.render();
// If something goes wrong
app.onError = function(err) {
$.writeln('ERROR ' + err);
};