4 Replies Latest reply on Aug 15, 2018 3:13 PM by Colin Flashman

    Run Spell Check before closing an InDesign file

    Masood.Ahmad Level 1

      Hello Everyone,

       

      I have a script created by Kai Rübsamen to generate an alert message before exporting a PDF:

       

      https://indesignsecrets.com/topic/alert-message-before-exporting-pdf

      <code>

      #targetengine "doSomethingInCase"

       

      app.addEventListener("beforeExport", onExport);

       

      function onExport(event) {

        var result = confirm("Have you check the file thoroughly before exporting the PDF?", true, "WARNING");

       

        if (result == true) {

        return

        };

        else (result == false) {

        event.stopPropagation();

        event.preventDefault(); 

        };

        return;

      }

      </code>

       

      The script works great! Thanks once again Kai for your support.

       

      I do remember I use to have a script that prompts me to run spell check before closing the file. Even it opens up the 'Check Spelling' dialog box for the user. Unfortunately it got lost somewhere and I'm unable to edit the above script.

       

      Can someone edit the above script to open up the Check Spelling dialog box before closing (onClose) the file.

       

      Thanks in advance,

      Masood

        • 1. Re: Run Spell Check before closing an InDesign file
          Masood.Ahmad Level 1

          I also tried this but it seems it only works on CS3. I have versions from CS4 to CC 2018

           

          Prompt to Spell Check Before Printing, Save and/or Close Document?

          • 2. Re: Run Spell Check before closing an InDesign file
            Colin Flashman Adobe Community Professional

            change the add.EventListener to the following:

             

            app.addEventListener("beforeClose", confirmClose);

             

            source: How to script a popup box before closing a document - InDesign - Graphic Design Stack Exchange

             

             

            • 3. Re: Run Spell Check before closing an InDesign file
              Masood.Ahmad Level 1

              Hi Colin,

               

              Thanks for looking into this. First, I got confused in which script you were asking to incorporate this change. Finally, I made the change in this script, but it is still not working. I also try adding the 'myCheckSpellHandler, false' in front of it but got an error in both the cases.

               

              /* CheckSpelling.jsx

              Version 1

              This script is written to remind a user to spell-check the current document.

              Put this script into Startup scripts folder and restart InDesign if it's running. */

               

              #target indesign

              #targetengine "session"

               

              var myLastDoc;

              var myConfirm;

              //app.addEventListener("beforeClose", confirmClose);

              //var myCheckSpellEvList = app.menuActions.item("Check Spelling...").addEventListener("beforeInvoke", myCheckSpellHandler, false);

              var myCheckSpellEvList = app.menuActions.item("Check Spelling...").app.addEventListener("beforeClose", confirmClose);

              var myBeforeCloseEvList = app.addEventListener("beforeClose", myBeforeCloseHandler, false);

              var myAfterCloseEvList = app.addEventListener("afterClose", myAfterCloseHandler, false);

               

              function myBeforeCloseHandler(myEvent){

                 myConfirm = false;

                 if (!eval(myEvent.parent.extractLabel("SpellingChecked")) && myEvent.parent.saved == true){

                    myLastDoc = myEvent.parent.fullName;

                    myConfirm = confirm("Do you want to check spelling now?", false, "You forgot to check spelling!");

                 }

              }

               

              function myAfterCloseHandler(myEvent){

                 if (!eval(myEvent.parent.extractLabel("SpellingChecked"))){

                    if (myConfirm) {

                       app.open(myLastDoc);

                       app.menuActions.item("Check Spelling...").invoke();

                    }

                 }

              }

               

              function myCheckSpellHandler(myEvent){

                 app.activeDocument.insertLabel("SpellingChecked", "true");

              }

               

              Screen Shot 2018-08-15 at 7.51.57 PM.png

              • 4. Re: Run Spell Check before closing an InDesign file
                Colin Flashman Adobe Community Professional

                Hi Masood

                 

                referring to your opening post only, replace this line:

                 

                app.addEventListener("beforeExport", onExport);

                 

                with this one:

                 

                app.addEventListener("beforeClose", confirmClose);

                 

                 

                in the script in your second post, the very line I've asked you to add, you've cancelled it out by adding the // in front of it (this means it will ignore this line). A few lines down, you've created the variable  myCheckSpellEvList which is meant to call the eventlistener, but nowhere else in the script is that variable asked to actually do anything.