launchd process using aerender exits early I'm trying to run aerender (After Effects' command-line renderer) via launchd to render a video on a timed interval.  The command works fine in Terminal.  In launchd - even when I use screen -d -m ... - it always exits early.  Here's my setup.

Skip to bottom for things I've already tried.

plist for launchd:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;com.home.VideoGenerator&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
      &lt;string&gt;/Users/home/Developer/VideoGenerator/exec/render.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;KeepAlive&lt;/key&gt;
    &lt;false/&gt;
    &lt;key&gt;StartInterval&lt;/key&gt;
    &lt;integer&gt;300&lt;/integer&gt;
    &lt;key&gt;StandardErrorPath&lt;/key&gt;
    &lt;string&gt;/var/log/com.home.VideoGenerator.err.log&lt;/string&gt;
    &lt;key&gt;StandardOutPath&lt;/key&gt;
    &lt;string&gt;/var/log/com.home.VideoGenerator.out.log&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;


render.sh script:

#!/bin/bash
/Applications/Adobe\ After\ Effects\ CC\ 2018/aerender -project /Users/home/Developer/VideoGenerator/resource/video.aep -comp ExportMe -output /Users/home/Developer/VideoGenerator/output/video.mov -OMtemplate Output


Output:

Here is what normal output looks like, when I run ./render.sh from the command line:

aerender version 15.0.1x73
PROGRESS: Launching After Effects...
PROGRESS: ...After Effects successfully launched
PROGRESS: Adding specified comp to Render Queue
PROGRESS:  4/2/18 8:41:57 AM PDT: Starting composition ExportMe.
...


This is truncated.  It also outputs composition settings and render progress, always successful.  Nothing useful for this purpose.

Here's the logged output when I run it from launchd:

aerender version 15.0.1x73
PROGRESS: Launching After Effects...
PROGRESS: ...After Effects successfully launched


And that's it.  (In reality I'm running this in a context where I can log the exit code and it's always 0.  For this purpose I have drastically simplified the project to what you see here, and it still doesn't run).

Things I've tried:


Set KeepAlive to true in the plist


This just relaunches the process after it exits

Add /dev/null as the StandardInPath in the plist (as per this post)


Still exits early

Add -i and -c to the beginning of ProgramArguments (from the same post as above)


Command doesn't run

Set AbandonProcessGroup to true in the plist


Still exits early

Append &amp; to put the task in the background


Silences output

Launch aerender with screen -d -m ...


Using the -L flag and checking the log, the output is the same; it stops after aerender launches After Effects and then exits before rendering.



Running ps aux | grep aerender shows over 20 processes running (probably from all the times I've executed the script), most of them aerendercore.  But no output, no video.

What am I doing wrong?
(Edited/Updated)

According to this thread on StudioSysAdmins, the problem I'm running into is because of aerender's reliance upon the Window Manager.


  Aerender is a hack that wraps the entirely GUI based After Effects
  application with a basic command line render interface. The AE core
  itself still depends directly on the Window Manager.
  ...


-Robin Scher

I ended up getting around this by using AppleScript (osascript) in the property list like so:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    ...
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
      &lt;string&gt;/usr/bin/osascript&lt;/string&gt;
      &lt;string&gt;/absolute/path/to/run.applescript&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;KeepAlive&lt;/key&gt;
    &lt;false/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Here is what run.applescript looks like:

tell app "/Applications/Utilities/Terminal.app"
  set w to do script "/Users/home/Developer/VideoGenerator/exec/render.sh; exit 0"
  repeat
    delay 1
    if busy of w is false then exit repeat
  end repeat
  #display dialog "finished"
end tell


I tell launchd to use osascript to run aerender in the context of a Terminal window.  A little convoluted, but it works!