Copy link to clipboard
Copied
Indesign jsx seems to be a bit more advanced than it's Photoshop sibling, which is what I'm used to.
Is there a quick one liner to make a filepath into a nice Windows one? ie
Turn
C:\\some%20folder/anotherFolder\\somefile.txt
into
C:\some folder\anotherFolder\somefile.txt
Without having to rely on regex to fix each thing (unifided slashes, %20, etc) as you go?
var afileName = "C:\\some%20folder/anotherFolder\\somefile.txt"
// var resolvedPath = resolve(afileName);
// var normalizedPath = path.normalize(afileName );
var nicePath = decodeURIComponent(afileName);
// Replace all front slashes with back slashes. We are Windows
nicePath = nicePath.replace(/\//g, "\\");
// replace %20 with space
// nicePath = nicePath.replace(/%20/g," ");
alert(nicePath);
Nope. You'll have to work with what you've got: use decodeURIComponent() (or decodeURI()) to decode all hex characters, then fix the slashes.
Copy link to clipboard
Copied
Nope. You'll have to work with what you've got: use decodeURIComponent() (or decodeURI()) to decode all hex characters, then fix the slashes.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I'm writing a text file. It's a filepath from the source folder of the InDesign file + the name of the Indesign File with a text file extension (instead of a .indd)
Copy link to clipboard
Copied
I'm writing a text file. It's a filepath from the source folder of the InDesign file + the name of the Indesign File with a text file extension (instead of a .indd)
By @Ghoul Fool
What returns app.activeDocument.fullName?
Copy link to clipboard
Copied
Once opened it says it has no fullName. 🙂 But after saving (old file done on previous version of Indd, me thinks) it remorts it in the form:
/c/some%20folder/my%20file.indd
Copy link to clipboard
Copied
Once opened it says it has no fullName. 🙂 But after saving (old file done on previous version of Indd, me thinks) it remorts it in the form:
/c/some%20folder/my%20file.indd
By @Ghoul Fool
So INDD has been converted from some older version?
Copy link to clipboard
Copied
ExtendScript has the File class for working with file paths.
There is a File.decode() method that should deal with your %20 .
Likely you won't need it, the constructor is very forgiving.
.You'd create an instance with its constructor function - no need for "new", then access any property.
The fsName property is closest you can get for the platform specific name.
var nicePath = File(afileName).fsName
Other properties are listed here
Above should be the same for PhotoShop and InDesign.
As your comments mention modern fs functions, InDesign jsx can also call the UXPSCRIPT language using the app.doScript method. I think PhotoShop is still missing such a method.
You'd call the UXPScript using
var nicePath = app.doScript("yadda",ScriptLanguage.UXPSCRIPT, [afileName]);
The "yadda" part can either refer to a script file or it can be the actual script code.
This won't be a neat single line though, you have to know and use plenty require() to get going at all.
To get started, passing arguments and the result is more, umm, elaborate.
UXP/UXPScript is also designed with security in mind, as opposed to developer convenience.
Have a read at some examples before you go down that road. Reference to the fs and path modules is linked at the bottom of that page. Actual code left as exercise. 😉
If you want to avoid the doScript part and start in modern script, you can also do that. Name your script file with ".idjs" extension rather than ".jsx" and stick to the new style.