3 Replies Latest reply on Jun 25, 2008 7:47 PM by (amitvyawahare)

    About Files

    Level 1

      My name is Amit. I am scripting InDesign CS3 using JavaScript in the OS X environment.
      I am opening a file using app.open(File("~/Desktop/minu/Amit-TOC.indd"));

      If such file is not present my script will come up with an error.
      What i want is if such file is not present. Program should automatically quit without giving any error.

        • 1. Re: About Files
          Level 1
          Hi Amit,

          Use try...catch, like this:


          There are other ways to do it--you could check for the existence of the file first. Take a look at the File and Folder reference in the JavaScript Tools Guide.


          • 2. Re: About Files
            Loic.Aigon Adobe Community Professional
            Hi Amit,
            Ole is right.
            In my humble opinion, it's a weird project to close your program if the file is not found. Don't you want to keep working on indesign afterall ?
            try/catch is a intersting technique to get info when you face a boring bug. But for that simple instruction,you can choose to do that :
            var myfile = File("~/Desktop/minu/Amit-TOC.indd");
            /* you may not want to be warned for the non presence of the file
            alert("Sorry, the file may have been displaced or removed !")
            // Or better
            // File.openDialog("Pick a file please...");
            • 3. Re: About Files
              Level 1
              Thank you ole and loic.
              I will try to use both method in my script.