I want the script to add layers to the open composition.
I want to make the script work only if the "Timeline" panel is highlighted.
I add layers like this:
But if the composition is selected in the "Project" panel, then the layer will be created in it.
It can be done so that in this case alert is displayed "select the timeline"; ?
is the composition selected in the project is the same as the activeItem?
You can 'force' AE to make composition active, by calling:
where 'curComp' should be comp item. Accordingly, you could grab selection from the project panel and use it for activating the viewer.
curComp = app.project.selection;
where selection would be selected item in the project panel, assuming its composition.
Whole scenario below, assuming that your selected comp in the project panel actually matches the one which you want to add item to. If it does not necessarily matches - then slight adjustments could be made.
var curComp = app.project.selection;