Copy link to clipboard
Copied
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"
};
};
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
@rob day can ypu please help us with your expertise on Applescript.
-Manan
Copy link to clipboard
Copied
Clarification: The code works fine up to InDesign version 20.1. It stops working with version 20.2.
Copy link to clipboard
Copied
Just guessing - HFS vs POSIX path problem?
Copy link to clipboard
Copied
It looks to me like Folder.fsName returns a POSIX path and that do shell script uses a POSIX path...
Copy link to clipboard
Copied
It looks to me like Folder.fsName returns a POSIX path and that do shell script uses a POSIX path...
By @AndreaParaboni
Better let us see some output.
I hope the following AppleScript survives the forum software.
tell application id "com.adobe.indesign"
set f1 to full name of active document
log class of f1
-- class furl
set p1 to POSIX path of f1
set h1 to do shell script "/bin/echo -n " & quoted form of p1 & " | hexdump -C"
tell application "Finder" to set f2 to container of (f1 as alias)
log class of f2
-- folder
set p2 to POSIX path of (f2 as alias)
set h2 to do shell script "/bin/echo -n " & quoted form of p2 & " | hexdump -C"
set f3 to do script "app.activeDocument.fullName" language javascript
log class of f3
set p3 to POSIX path of f3
set h3 to do shell script "/bin/echo -n '" & p3 & "' | hexdump -C"
set p4 to do script "app.activeDocument.fullName.fsName" language javascript
set h4 to do shell script "/bin/echo -n '" & p4 & "' | hexdump -C"
set p5 to do script "app.activeDocument.fullName.parent.fsName" language javascript
set h5 to do shell script "/bin/echo -n '" & p5 & "' | hexdump -C"
log return & h1 & return & h2 & return & h3 & return & h4 & return & h5 & return
display dialog h5
end tell
Launch AppleScript Editor
Create a new script, paste the code
At the bottom, switch to last choice "Responses" or whatever localization made from it to see intermediate values and log output.
Run the script with InDesign having an active document.
The most interesting part is the final output of the hexdumps.
If your original script fails only with specific folders, adjust the javascript for p5 accordingly to look at them, or add the h5 related lines including the display dialog line to the applescript part of your own script.
If you are thrill seeker, re-run the script with a document or parent folder using some perfectly allowed characters
(Screenshot from Finder)
and watch your approach of passing around fsName as posix path fail.
Copy link to clipboard
Copied
Here some ideas for error handling:
// jsx multi-line string
script = """
set errStr to ""
set errNum to 0
try
tell application "Finder" to get path to desktop
set d to the result
fail
on error errorStr number errorNum
set errStr to errorStr
set errNum to errorNum
end try
return {d, POSIX path of d, 1, "Hello, world", errStr, errNum}
""";
Copy link to clipboard
Copied
Same result for Folder.fullName...
Copy link to clipboard
Copied
Yep, a POSIX issue, we had that recently. I could not find where it was discussed, though.
In theory, for the AppleScript side, you should be able to pass a file rather than the .fsName string.
AppleScript itself then has some convoluted conversion "quoted form of POSIX path of myFile" for passing to the shell script, rather than manually adding quotes. Mac folder names may contain quotes …
In practice you better test what comes along in your particular InDesign version, and I won't install 20.2 for that.
@Manan Joshi The AppleScript part could be a workaround attempt for a crash.
Better rewrite that to a simple function rather than change the prototype function as Marc did.
Copy link to clipboard
Copied
Do I deserve a correct answer? 😄
Copy link to clipboard
Copied
Thanks everyone for the suggestions. What concerns me is that the code has been working fine in InDesign for many years... until version 20.1. From the next version (20.2) it stops working. If there were any errors in the code they would have emerged. Or not?
Copy link to clipboard
Copied
Thanks everyone for the suggestions. What concerns me is that the code has been working fine in InDesign for many years... until version 20.1. From the next version (20.2) it stops working. If there were any errors in the code they would have emerged. Or not?
By @andrea.paraboni
https://helpx.adobe.com/uk/indesign/kb/user-dictionaries-missing-hfs-path-dropped.html
Copy link to clipboard
Copied
As far as I can see, there are only POSIX paths in the original script.
Copy link to clipboard
Copied
Thanks for the article @Dirk Becker the interesting thing is I tried this code on InDesign version 2022 and it also gave the same error. So I am not sure that this is limited to 20.2 and beyond.
-Manan
Copy link to clipboard
Copied
@Manan Joshi The AppleScript part could be a workaround attempt for a crash.
Better rewrite that to a simple function rather than change the prototype function as Marc did.
By @Dirk Becker
I do agree with Dirk. The 'prototype' approach only makes sense in a framework (like IdExtenso) or if you're troubleshooting a client script (or jsxbin!) with a hundred thousand lines of code that may call folder.create() anywhere 😉
Copy link to clipboard
Copied
Log the folder value, then try to run the same function with this value in a separate script and see if it works.
Copy link to clipboard
Copied
Upgrading to 20.3 fixes everything! This was a bug in InDesign 20.2. Thanks everyone.