Skip to main content
Participant
April 14, 2025
Answered

Why does this code not work with a version of InDesign?

  • April 14, 2025
  • 3 replies
  • 1735 views

Hello everyone, I'm trying to understand why the code I attach works perfectly with InDesign 19.x and does not work with Indesign 20.x (see image)

Both versions of InDesign are on MacOS Ventura 13.7.5. Is it perhaps a bug in the latest version of InDesign?

Is it a bug in the latest version of InDesign or a stupid mistake of mine? Thanks to all.

Here is the code:

 

function createFolder(folder) {
    var script = "";
    script += "try\r";
    script += "do shell script \"mkdir \" & quote & item 1 of arguments & quote\r";
    script += "tell application id \"com.adobe.InDesign\"\r";
    script += "tell script args\r";
    script += "set value name \"success\" value \"true\"\r";
    script += "end tell\r";
    script += "end tell\r";
    script += "on error\r";
    script += "tell application id \"com.adobe.InDesign\"\r";
    script += "tell script args\r";
    script += "set value name \"success\" value \"false\"\r";
    script += "end tell\r";
    script += "end tell\r";
    script += "end try\r";
    app.doScript(script, ScriptLanguage.applescriptLanguage, Array(folder.fsName));
    if(app.scriptArgs.getValue('success') == "false") {
        return false;
    } else {
        return true;
    }
}

if(document.saved) {
     var file = new File(document.filePath + "/New folder");
} else {
     var file = new File("~/Documents/New folder");
}
var saveFile = file.saveDlg(
    "Create folder",
    "All files:*"
);
if(saveFile) {
    var folder = new Folder(saveFile.fullName);
    if(folder.exists) throw {
        message: "The folder '" + folder.name + "' already exists.",
        level: "Warning"
    };
    if(!createFolder(folder)) throw {
        message: "Error creating folder.",
        level: "Error"
     };
};

 

 

Correct answer andrea.paraboni

Upgrading to 20.3 fixes everything! This was a bug in InDesign 20.2. Thanks everyone.

3 replies

andrea.paraboniAuthorCorrect answer
Participant
April 22, 2025

Upgrading to 20.3 fixes everything! This was a bug in InDesign 20.2. Thanks everyone.

Participant
April 14, 2025

Clarification: The code works fine up to InDesign version 20.1. It stops working with version 20.2.

Robert at ID-Tasker
Legend
April 14, 2025

Just guessing - HFS vs POSIX path problem? 

 

Participant
April 14, 2025

It looks to me like Folder.fsName returns a POSIX path and that  do shell script uses a POSIX path...

Community Expert
April 14, 2025

I am not sure why the code does not work in one version and works in other. However, you don't need a shell script to create a new folder, you can use the folder object. Try the following

if(document.saved) {
     var file = new File(document.filePath + "/New folder");
} else {
     var file = new File("~/Documents/New folder");
}
var saveFile = file.saveDlg(
    "Create folder",
    "All files:*"
);
if(saveFile) {
    var folder = new Folder(saveFile.fullName);
    if(folder.exists) throw {
        message: "The folder '" + folder.name + "' already exists.",
        level: "Warning"
    };
    if(!folder.create()) throw {
        message: "Error creating folder.",
        level: "Error"
     };
};

-Manan

-Manan
Participant
April 14, 2025

Hi Manan, this code is taken from an application that performs other operations on folders, for example: move, copy, and delete (with all its content). For that I chose to use "do shell script" inside an Applescript script. It is complex (in my opinion) to perform operations on the file system using ExtendScript...

Community Expert
April 14, 2025

Ok, I tried this on my MAC and it did not execute for me on 2025 or even 2022 version of InDesign. So I am guessing this is some MAC permission issue. Not able to figure out yet as to what that is

-Manan

-Manan