// Isosceles_PasteClipboardIntoFootage.jsx
// Code generated by ChatGPT-5.5
// Date: June 2, 2026
// Description: This After Effects script will select the .MP4 layer and paste the clipboard contents. This will be applied to the comps that are selected in the Project window.
// IMPORTANT NOTE: This has only been tested with pasting an effect into an MP4 footage item within a comp. Only the first footage layer will be affected.

{
    app.beginUndoGroup("Paste Clipboard Into MP4 Layers");

    var proj = app.project;
    var items = proj.selection;

    if (items.length === 0) {
        alert("Please select one or more comps in the Project panel.");
    } else {

        for (var i = 0; i < items.length; i++) {

            if (!(items[i] instanceof CompItem))
                continue;

            var comp = items[i];

            // Deselect all layers first
            for (var d = 1; d <= comp.numLayers; d++) {
                comp.layer(d).selected = false;
            }

            var mp4Layer = null;

            // Find first MP4 layer
            for (var l = 1; l <= comp.numLayers; l++) {

                var layer = comp.layer(l);

                try {
                    if (
                        layer.source &&
                        layer.source.mainSource &&
                        layer.source.name &&
                        /\.mp4$/i.test(layer.source.name)
                    ) {
                        mp4Layer = layer;
                        break;
                    }
                } catch (err) {}
            }

            if (mp4Layer) {

                comp.openInViewer();

                mp4Layer.selected = true;

                // Make sure the comp viewer is active
                app.activeViewer.setActive();

                // Paste clipboard contents
                app.executeCommand(20); // Edit > Paste

                mp4Layer.selected = false;
            }
        }
    }

    app.endUndoGroup();
}