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

app.activeDocument.close(SaveOptions.yes); Questions

Advisor ,
Feb 12, 2019 Feb 12, 2019

Hello,

I have a couple of questions about app.activeDocument.close(SaveOptions.yes);

just want to know if there's any way to prevent the two issues below from happening or if there is a another method to access the Save As dialog window

1. In the dialog window if the cancel button is selected the document still closes.

2. If the cancel button is selected you'll recieve a javascript error.

Thanks in advance!

Mike

Screen Shot 2019-02-12 at 11.55.49 AM.png

TOPICS
Scripting
2.4K
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

correct answers 1 Correct answer

Community Expert , Feb 13, 2019 Feb 13, 2019

Hi Mike,

Technically you are not 'avoiding' the error, you are just handling it by doing the try catch, it means the error is thrown but the 'catch' part of your code is dealing with it.

Although the code you have posted doesn't make much sense as there are far too many {}

// a standard try....catch would look like this.

try

{

     app.activeDocument.save();

     exit();

}

catch (e)

{

}

Regards

Malcolm

Translate
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Hi Mike,

Has the document you are closing already been saved? (if not this will through an error as it can't save a file without a path, and therefore a file has to have been saved once for your code to work)

Regards

Malcolm

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
Advisor ,
Feb 12, 2019 Feb 12, 2019

Hi Malcolm,

No the document has not been saved, it's opened from a template through my code.

the method below works giving me access to the Save As dialog and avoids the javascript error If the cancel button is selected.

try {

app.activeDocument.save(); {

} {

       exit();

       }} catch (e) {

    }

Thanks,

Mike

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
Community Expert ,
Feb 13, 2019 Feb 13, 2019

Hi Mike,

Technically you are not 'avoiding' the error, you are just handling it by doing the try catch, it means the error is thrown but the 'catch' part of your code is dealing with it.

Although the code you have posted doesn't make much sense as there are far too many {}

// a standard try....catch would look like this.

try

{

     app.activeDocument.save();

     exit();

}

catch (e)

{

}

Regards

Malcolm

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
Advisor ,
Feb 13, 2019 Feb 13, 2019
LATEST

Hi Malcolm,

You're correct, I should have stated that the error is being handled by the try catch not "avoided". The extra {} came from me grabbed the try catch in from somewhere else in my code that contained a "if" and "else" and I neglected to properly clean it up.

Thanks,

Mike

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