Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

About Files

New Here ,
Jun 24, 2008 Jun 24, 2008
Hello,

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.

--Amit
TOPICS
Scripting
399
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 24, 2008 Jun 24, 2008
Hi Amit,

Use try...catch, like this:

try{
app.open(File("~/Desktop/minu/Amit-TOC.indd"));
}
catch(e){}

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.

Thanks,

Ole
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 25, 2008 Jun 25, 2008
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");
if(myfile.exists==true)
{
app.open(myfile);
}
/* you may not want to be warned for the non presence of the file
else
{
alert("Sorry, the file may have been displaced or removed !")
// Or better
// File.openDialog("Pick a file please...");
}
*/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 25, 2008 Jun 25, 2008
LATEST
Thank you ole and loic.
I will try to use both method in my script.

--Amit
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines