Copy link to clipboard
Copied
OSX 10.6 running InDesign CS5.5. Scripting using Javascript.
I'm almost finished a script to automate the ePub Export settings dialog box, but I'm having real problems setting the cover image.
epubExportPreferences.coverImageFile seems to require a colon separated absolute file path as a string. ie:
Macintosh HD:Users:*name of user*:Documents:
rather than the slash separated relative file path generated by myDocument.filePath, which returns ~/Documents/.
The cover image is always in the same folder as the InDesign file. Is there another way I can generate the file path to the InDesign document that would give me the full path? I can use theCoverFile.replace(/\//g,":") to swap out the slashes, it's the tilda I'm having issues with.
Thanks.
Tricky ...
The filePath property of a document returns a string by default but it is, in fact, a proper File object. And you can interrogate a File object for more than just the base path:
alert (app.activeDocument.fullName.fsName);
But -- a very big but -- this notation is still relative to the startup disk, and I get "/Users/[name]/Documents/test.indd", without the my local startup volume name "Macintosh HD". From an USB disk I get
/Volumes/USB Disk/test.indd
so in theory everything works fine, but
...Copy link to clipboard
Copied
Tricky ...
The filePath property of a document returns a string by default but it is, in fact, a proper File object. And you can interrogate a File object for more than just the base path:
alert (app.activeDocument.fullName.fsName);
But -- a very big but -- this notation is still relative to the startup disk, and I get "/Users/[name]/Documents/test.indd", without the my local startup volume name "Macintosh HD". From an USB disk I get
/Volumes/USB Disk/test.indd
so in theory everything works fine, but in practice you cannot get the name of your root drive! Oh well, you might as well assume it's always going to be the same and tack it on in front of the first ':' ![]()
Does it also bother you this setting requires the obsolete "old style" of path notation that Apple abandoned with OS X?
Since 2002, Mac OS X has been included with all new Macintosh computer systems. (wikipedia on "OS X")
What, does this specification really run 10 years behind?
Copy link to clipboard
Copied
I really don't understand why it's using antiquated notation, but the field doesn't seem to accept any other input (including passing the object directly). There are a lot of things about the ePub Export options that don't make total sense, I'm just happy that they allow you to set a cover page now, which they didn't in CS5.
Thanks for the fsName, I'll use that and manually tack on "Macintosh HD" and swap out the slashes. I'll just throw an alert and open the options if you are working on a file on the server (a rare occurrence).
Copy link to clipboard
Copied
Brilliant.
I've posted the final code for anyone looking for the same thing. I have mine nested in try blocks with contingencies, but this is the basic code:
var theCoverFile = "Macintosh HD" + myDocument.filePath.fsName + "/cover.jpg";
var theCoverFileWithColons = theCoverFile.replace(/\//g,":");
myDocument.epubExportPreferences.epubCover = EpubCover.EXTERNAL_IMAGE;
myDocument.epubExportPreferences.coverImageFile = theCoverFileWithColons;
Thanks so much. I know it only saves a few minutes, but I hate doing something again and again if I know it can be scripted!
Copy link to clipboard
Copied
I think you can put File instead of the string to the coverImageFile property.
I didn't tested this, but it should work. ![]()
Try this:
var theCoverFile = File(myDocument.filePath.fsName + "/cover.jpg");
myDocument.epubExportPreferences.epubCover = EpubCover.EXTERNAL_IMAGE;
myDocument.epubExportPreferences.coverImageFile = theCoverFile;
Hope that helps.
--
Marijan (tomaxxi)
Copy link to clipboard
Copied
If you called out to Applescript, you wouldn't have to worry if the file was on a remote volume:
var coverFilePath = app.doScript("tell application \"Finder\" to return POSIX file \"" + myDocument.filePath.fsName + "\" as text", ScriptLanguage.APPLESCRIPT_LANGUAGE);
Jeff
Copy link to clipboard
Copied
Hello everyone,
I have a question that you guys may or not know regarding the filepath for some of the .jsx scripts that I use on OSX. The path looks something like this:
var foobar = new File("/Macintosh HD/Users/greenrookie/test folder/" + myDocName);
This works fine. However, I also have a Xserve volume mounted on the desktop with 'Users' as the name. It therefore (copies or creates same folder structure) foobar to that volume too!
Is there a way to differentiate the path so it only creates to the computer and not the Xserve volume?
Many thanks!
Greenrookie
Copy link to clipboard
Copied
Ah, ok, the answer is here, 4 years ago. For anyone with the same problem.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more