I need to automate some process in Indesign, therefore I need a javascript script with simple feature: select all frame objects (no matter what kind of a content: both text and image), and add a stroke property to them. 3 px black stroke, for example.

It must be a simple task, but I am new at javascript. I've tried to modify other similar script, but It doesn't work:

var myDocument = app.activeDocument;
var selection = app.selection;
var selectionLength = selection.length;

var myColor =  myDocument.colors.item("C=0 M=0 Y=0 K=100");

try {
    } catch (e) {
        // Doesn't exist; add it.
        myColor = myDocument.colors.add({name: "C=0 M=0 Y=0 K=100", colorValue: [0, 0, 0, 100], model: ColorModel.PROCESS, space: ColorSpace.CMYK});


for (var n = 0; n <  selectionLength ; n++) {

    var mySelection = app.selection;

    mySelection.strokeWeight = 3;
    mySelection.enableStroke = true;
    mySelection.strokeColor = myColor;
    mySelection.strokeTint = 100;
    mySelection.strokeAlignment = StrokeAlignment.INSIDE_ALIGNMENT;


1 Answer 1


This script will select all frames and add a 3pt stroke that is black. For the script to work, the script assumes that you have a “Black” color swatch defined in your document. If you have a different name for your black swatch or if you want to use a different color, you’ll need to adjust the strokeColor variable accordingly.

// Target InDesign
#target indesign

// Function to apply stroke to all frames
function applyStrokeToAllFrames(doc, strokeWeight, strokeColor) {
    // Iterate over all page items
    for (var i = 0; i < doc.allPageItems.length; i++) {
        var item = doc.allPageItems[i];
        // Check if the item is a graphic or text frame
        if (item instanceof TextFrame || item instanceof Rectangle || item instanceof Oval || item instanceof Polygon) {
            // Apply stroke weight and color
            item.strokeWeight = strokeWeight;
            item.strokeColor = doc.swatches.item(strokeColor);

// Main script
if (app.documents.length > 0) {
    // Get the active document
    var doc = app.activeDocument;
    // Define stroke weight and color
    var strokeWeight = 3; // 3 px stroke weight
    var strokeColor = "Black"; // Stroke color
    // Apply stroke to all frames
    applyStrokeToAllFrames(doc, strokeWeight, strokeColor);
} else {
    alert("No documents are open. Please open a document and try again.");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.