7 Replies Latest reply on Aug 13, 2014 7:28 AM by greenrookie

    changing filePath format from slash to colon separators


      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.



        • 1. Re: changing filePath format from slash to colon separators
          [Jongware] Most Valuable Participant

          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. Re: changing filePath format from slash to colon separators
            @naomikennedy Level 1

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

            • 3. Re: changing filePath format from slash to colon separators
              @naomikennedy Level 1



              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!

              • 4. Re: changing filePath format from slash to colon separators
                Marijan Tompa [tomaxxi] Level 4

                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)


                • 5. Re: changing filePath format from slash to colon separators
                  absqua Level 4

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



                  • 6. Re: changing filePath format from slash to colon separators
                    greenrookie Level 2

                    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!



                    • 7. Re: changing filePath format from slash to colon separators
                      greenrookie Level 2

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


                      How to reference Macintosh HD in file path