// ISO_MoveTimeIndicatorFrames.jsx
// Artist: https://www.jasonfletcher.info/
// Code generated by ChatGPT-5.3
// Date: March 15, 2026
// Description: This After Effects script will open the selected comps in the Project window and move the Current Time Indicator to a user-specified frame.

{
    // Ask user for frame number
    var userInput = prompt("Move CTI to which frame?", "20");

    if (userInput !== null) {

        var targetFrame = parseInt(userInput, 10);

        if (!isNaN(targetFrame) && targetFrame >= 0) {

            // Start undo group
            app.beginUndoGroup("Move CTI to Frame " + targetFrame);

            // Get selected items
            var selectedItems = app.project.selection;

            if (selectedItems.length === 0) {
                alert("Please select at least one composition in the Project panel.");
                app.endUndoGroup();
            } else {

                var affectedComps = 0;

                for (var i = 0; i < selectedItems.length; i++) {
                    var item = selectedItems[i];

                    // Only operate on compositions
                    if (item instanceof CompItem) {

                        // Convert frame → seconds
                        var targetTime = targetFrame * item.frameDuration;

                        // Open comp in viewer
                        item.openInViewer();

                        // Move CTI
                        item.time = targetTime;

                        affectedComps++;
                    }
                }

                // End undo group
                app.endUndoGroup();

                // Final summary alert
                alert(
                    "Target frame set: " + targetFrame + "\n" +
                    "Comps affected: " + affectedComps
                );
            }

        } else {
            alert("Please enter a valid non-negative frame number.");
        }
    }
}
