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:
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
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?
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).
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!
I think you can put File instead of the string to the coverImageFile property.
I didn't tested this, but it should work.
var theCoverFile = File(myDocument.filePath.fsName + "/cover.jpg"); myDocument.epubExportPreferences.epubCover = EpubCover.EXTERNAL_IMAGE; myDocument.epubExportPreferences.coverImageFile = theCoverFile;
Hope that helps.
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);
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?