There are situations where it would be useful to burn the name of each shot's source footage into a render. It would be advantageous if we could do this with a single layer which could be switched off for final render. So our design goal is to come up with a way to display the source name of the current clip. If the current clip doesn’t have a source (a solid or a text layer, for example), we want to display the layer name. If there is no visible layer at the current time, we want to display nothing.

We’ll use a text layer and apply an expression to the Source Text property. We’ll have the expression move through the layer stack from top to bottom until it finds a layer that is visible at the current time. Of course we’ll want the expression to ignore its own text layer. 3D layers will mess things up (because of the arbitrary stacking order), so we won't worry about them in this design.

txt = "";
for (i = 1; i <= thisComp.numLayers; i++){
  if (i == index) continue;
  L = thisComp.layer(i);
  if (! (L.hasVideo && continue;
    txt =;
    txt =

Text layer displays source name of top-most visible layer.

Swan image courtesy Candice Walker

Note the use of the JavaScript try / catch construct. This allows you to trap conditions within an expression that would normally generate errors and cause the expression to be disabled. The catch(err) part of the construct is where you declare what you want to happen in case of an error. In our case, if we try to reference the source of a layer that doesn't have one, it will generate an error. Here we trap the error and just use the layer name instead.