// ISO_WorkAreaStartToSpecificFrame.jsx
// Artist: https://www.jasonfletcher.info/
// Code generated by ChatGPT-5
// Date: October 9, 2025
// Description: This After Effects script will move the "Work Area Start" to a user-defined frame for all selected comps in the Project window.

(function moveWorkAreaStartToUserFrame() {
    app.beginUndoGroup("Move Work Area Start to User Frame");

    var items = app.project.selection;
    var movedCount = 0;

    if (items.length === 0) {
        alert("Please select one or more compositions in the Project panel.");
        app.endUndoGroup();
        return;
    }

    // Ask user ONCE for desired frame
    var input = prompt("Enter the frame number to move the Work Area Start to:", "5");

    if (input === null) {
        app.endUndoGroup();
        return; // user cancelled
    }

    var targetFrame = parseInt(input, 10);

    if (isNaN(targetFrame) || targetFrame < 0) {
        alert("Invalid frame number entered.");
        app.endUndoGroup();
        return;
    }

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

        if (comp instanceof CompItem) {
            var frameDuration = 1 / comp.frameRate;
            var targetTime = frameDuration * targetFrame;

            comp.workAreaStart = targetTime;
            movedCount++;
        }
    }

    alert(
        "Comps processed: " + movedCount + "\n" +
        "Work Area Start set to frame: " + targetFrame
    );

    app.endUndoGroup();
})();