// ISO_MoveTimeIndicatorSeconds.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 time (measured in seconds).

{
    // Ask user for target time in seconds
    var userInput = prompt("Enter the time (in seconds) to move the CTI to:", "20");

    // Exit if user cancels
    if (userInput === null) {
        alert("Operation cancelled.");
    } else {

        var targetTime = parseFloat(userInput);

        if (isNaN(targetTime)) {
            alert("Please enter a valid number for seconds.");
        } else {

            var processedCount = 0;

            // Start undo group
            app.beginUndoGroup("Move CTI to " + targetTime + " seconds");

            // Iterate over selected items in the Project panel
            var selectedItems = app.project.selection;

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

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

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

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

                        // Move CTI
                        item.time = targetTime;

                        processedCount++;
                    }
                }

                // Final summary alert
                alert(
                    "Target time set: " + targetTime + " seconds" + "\n" +
                    "Comps affected: " + processedCount
                );
            }

            // End undo group
            app.endUndoGroup();
        }
    }
}
