The Great Folder Fiasco: A Tale of InDesign 20.1 and macOS
January 31, 2025 | Snippets | en
As a developer or InDesign scripter, you know how important it is to stay up-to-date on the latest changes and issues affecting your work. Here we'll tackle an obscure, low-level issue affecting InDesign 20.1 on macOS…
Until recently, the low-level ExtendScript method Folder.prototype.create()
worked reliably across all platforms, creating entire folder paths from scratch. With a simple line of code, you could create a hierarchy like this:
// dir1 and/or dir2 will be created too, if needed. var myFolder = new Folder(Folder.myDocuments + '/dir1/dir2/dir3'); myFolder.create();
But, alas, those carefree days are behind us. As of InDesign 20.1 on macOS, our trusty Folder.prototype.create()
has become a bit unpredictable. It's like it's playing a game of “folder roulette” — creating only the highest missing folder in the hierarchy, but not the ones below it.
For example, if you try to create a folder like ./dir1/dir2/dir3, it might only create dir1, or dir2 if dir1 already exists. And even if it doesn't throw any errors, you can't always rely on myFolder.exists
being true afterwards.
This change has the potential to wreak havoc on your scripts, especially those that rely on predictable folder creation. Some well-established scripts started to bug for no apparent reason after updating to ID 20.1.
Patching the Faulty Method
Until Adobe fixes the issue, you can patch the faulty method and restore its consistency. IdExtenso already has it implemented, but here's a standalone solution you can use:
if( 'Macintosh' == File.fs && 20.1 <= parseFloat(app.version) ) { // Backup original method. Folder.prototype.__create__ = Folder.prototype.create; // Patch. Folder.prototype.create = function create() { return this.exists || ( (null === this.parent || this.parent.create()) && this.__create__() ); }; }
Note. - This patch works by directly rewriting the native method. In ExtendScript, it's possible to override built-in prototypes, but be careful not to cause any conflicts with other scripts or code. In this case, we're coding a new method that checks if the parent folder exists and creates it if necessary. If the parent folder doesn't exist, it recursively calls create()
on the parent folder until all the required subfolders are created. The original method, __create__()
, is invoked whenever a pure subfolder creation is required.
So, there you have it — a charming bug and a temporary fix to save the day. May your scripts be folder-creation-friendly, and may Adobe fix this issue soon!
→ More about Folders in ExtendScript: Folder Object Reference