Skip to main content
Inspiring
January 2, 2012
Answered

changing filePath format from slash to colon separators

  • January 2, 2012
  • 2 replies
  • 4278 views

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.

This topic has been closed for replies.
Correct answer Jongware

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?

2 replies

Inspiring
August 8, 2014

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

Inspiring
August 13, 2014

Ah, ok, the answer is here, 4 years ago. For anyone with the same problem.

How to reference Macintosh HD in file path

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
January 2, 2012

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?

Inspiring
January 2, 2012

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).

Inspiring
January 2, 2012

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!