Skip to main content
Participating Frequently
April 14, 2014
Answered

afterfx command line "restores" maximized window - any way to duplicate ExtendScript invocation?

  • April 14, 2014
  • 4 replies
  • 4323 views

Hi all,

I am controlling After Effects CC from another application by invoking JavaScript files from the command line. But the command *always* restores the maximized window of After Effects. That is, if the After Effects application is maximized, it always *restores* it, every time I invoke the JavaScript file through the command line (e.g. through Windows cmd prompt or through my application). When I execute the same JavaScript file through ExtendScript IDE, it doesn't do this erronous behaviour.

For example: "AfterFx.exe -r C:\path\showDialog.jsx"

Contents of showDialog.jsx:

----------

alert("Showing Dialog from JSX file");

----------

My question is: Is there *any way* to mimic what ExtendScript does to invoke JavaScript files?

From listening on Windows processes, it seems that ExtendScript tacks on some JavaScript code, dynamically, to do the execution (i.e. couldn't trace any command line processes/arguments). But I can't seem to figure out what exact JavaScript code it invokes. ExtendScript also seems to be working via Bridge.

I get the same "restore window" behaviour when I try to use "-s" argument with the JavaScript expression passed as a string argument or if I use "AfterFx.com" instead of "AfterFx.exe". I couldn't find any documentation for what command line parameters are supported for AfterFx (other than "-r" and "-s") and what Extend Script might be doing exactly to invoke the .jsx files. I managed to take a peek at the executable binary of AfterFx.exe (through a hex editor) and noticed the following switches.

-rquiet, -noerr, -noui, -debug, -livelink, -selflink, -headlessonly, -rquiet, -rq, -mp

But I couldn't get the "window restoring" behaviour to stop with any of the parameters.

Any advice will be really appreciated.

Thanks.

Correct answer Justin Taylor-Hyper Brew

If you need another instance of After Effects that doesn't interrupt your user's actions in the current instance, then use the -m flag:

AfterFX.com -noui -m -s "alert('test')"

or

AfterFX.exe -noui -m -s "alert('test')"

4 replies

VertigoJC
Inspiring
July 24, 2019

It's been a little over a year since the last update here.

Has anyone figured this out? I'm running into this same problem while trying to write tools that interact with our shot tracking system at our studio.

This "restoring" of the window basically makes this unusable because artists don't want their windows to be changing sizes while they are working.

Has anyone from Adobe weighed in on this to explain the strange behavior when calling afterfx.exe from command line?

Justin Taylor-Hyper Brew
Community Expert
Community Expert
July 25, 2019

VertigoJC​ What are you trying to do with this background function? Can you use aerender.exe instead? (also, might wanna start a new thread on this topic)

Justin Taylor-Hyper Brew
Community Expert
Community Expert
July 25, 2019

We are developing a standalone "sidekick" app that integrates with our shot tracking database. I want to use the command line to call scripts with -r or run some code with -s to update existing variables in AE or to fire off certain scripts to notify artists of changes in their project. That part of it all works except for the fact that AE gets knocked out of maximized mode when it is called from the command line, which is incredibly frustrating for the artist working on it.


CLI commands are best suited for standalone operations like batch/procedural rendering and such. What you're describing would be much easier achieved through a persistent script or invisible CEP extension that can communicate with your external app via WebSockets.

Participant
April 5, 2018

Still... but that doesn't really solve the problem, does it? I am fighting with this issue as well.... Still no solution, other than check the state of the window before running a command, then run the command, and then force set the window to the same state... haven't tried it yet, but in theory it should work, though the movement of the window will probably be visible.

Known Participant
June 5, 2018

I came up with basically what you suggested using AutoHotkey and a keyboard shortcut. Here an example Autohotkey script:

#1::                                                                ;Shortcut combination is Windows key + 1

{

WinGet, minmax_state, MinMax, A                ;Gets current Min/Max state of active window

Run AfterFX.exe -r scriptfile.jsx                     ;runs script

if minmax_state = 1                                        ;if window was previously maxmized

{

Sleep, 100                                                     ;sleep so script is at least starting to run

WinMaximize, A                                             ; maximizes active window

}

Return

}

There's a visible restoring and then maximizing back like you predicted but it's pretty quick.

You do need Autohotkey installed, although you can super easily convert an Autohotkey script to an exe file (just right click script file -> compile) if you need to move it around.

Not sure how it'll work with slow scripts - sleep might need to be slightly longer.

Still - not a solution, just a workaround

Participant
January 29, 2015

Hey adobe_sur2,

I would like to know if you have found a solution yet.

Thanks.

Legend
April 14, 2014

If you use the -noui switch you shouldn't see the UI at all.  Your script requires AE to show an alert dialog so it probably won't work though.  Try making your script do something other than alerting the user and see if the problem persists.

Participating Frequently
April 14, 2014

Hi again,

Thanks for the comment. I was using the "alert" command just as a example but I did try it with other scripts which doesn't show a dialog message, with the "-noui" argument. The result is the same. I tried several combinations with "-noui", "-rq" and "-rquiet".

For example, here is one script which increases the frame duration: AfterFx.exe -r C:\path\frameDuration.jsx

--

Content of frameDuration.jsx:

--

var currFrameDuration = app.project.activeItem.frameDuration;

app.project.activeItem.frameDuration = currFrameDuration + 0.01;

--

Also, note that even if I don't put any argument and just execute AfterFx.exe (from the command line or from the start menu), the behaviour is the same - that is, if the After Effects application was maximized, it restores the window to the last known window which wasn't maximized. So I am wondering whether this is just how they coded AfterFx - to restore the window if the executable is launched while the application is still running. But if that is the case, I don't know how to control After Effects with scripts, from my own desktop application. If I put a script in the startup folder and use the Socket object to listen on a port for commands (from my desktop application), then it freezes the After Effects UI completely. I think I read somewhere that ExtendScript uses Bridge talk protocol to execute JavaScript files from the IDE. But I can't seem to find details as to how my desktop application can replicate what ExtendScript does to execute JavaScript files.

Thanks.

Legend
April 15, 2014

Have you tried using something like PsExec to lauch AfterFX.exe?  There are a good number of switches you can use there to handle how the process is launched.  Also, maybe try to use Windows' command interpreter (cmd) to launch AfterFX.exe in the background.

Check out PsExec here:

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

--Arie