Skip to main content
Participant
January 29, 2025
Question

indesign scripts not working

  • January 29, 2025
  • 1 reply
  • 195 views

Hi guys, 
I am very new, and am trying to get ANY script to run inside of inDesign. 

My first script looks like this:

//@target indesign
//@targetengine "session"

(function() {
if (typeof app === "undefined") { return; }

try {
var doc = app.documents.add();

with(doc.documentPreferences) {
pageSize = "a4";
facingPages = false;
}

var textFrame = doc.pages[0].textFrames.add();
textFrame.geometricBounds = [50, 50, 500, 500];
textFrame.contents = "my content";

var file = new File("~/Desktop/Generated_Document_1738124549947.indd");
doc.save(file);
} catch(error) {
if (typeof alert !== "undefined") {
alert("Error: " + error);
}
}
})();

 

 

when i try to run this litterally nothing happens at all.

Then i tried a "hello world" and get the following:

 

that code was this:

//@target indesign

(function runNow() {
    try {
        if (typeof app === "undefined") {
            throw new Error("InDesign is not available.");
        }

        var doc = app.documents.add();
        var textFrame = doc.pages[0].textFrames.add();
        textFrame.geometricBounds = [50, 50, 250, 500];
        textFrame.contents = "Hello World from InDesign!";

        var filePath = new File(Folder.desktop + "/HelloWorld.indd");
        doc.save(filePath);

        app.alert("Document created and saved at: " + filePath.fullName);

    } catch (error) {
        app.alert("Error: " + error.message);
    }
})();

 

I am running inDesign cloud v20 on a windows pc.



1 reply

m1b
Community Expert
Community Expert
January 29, 2025

Hi @fantastic_Marshmallow1587 I believe the code you've written is ExtendScript, which should be saves with a .js or .jsx file extension. I think you may have saved with an .idjs extension, which is reserved for the newer UXP code. Try changing the extension.

- Mark

 

P.S. If instead you *intend* to write UXP code, then you will need to search for UXP code examples and avoid ExtendScript. Sorry it is confusing situation at the moment between the two scripting systems.