Skip to main content
Known Participant
October 7, 2010
Question

Spell Check

  • October 7, 2010
  • 3 replies
  • 2477 views

Hi All,

Below code is working if spell check is not done, then it does not allow user to close the file automatically opens the document. Problem I am facing with after running spell check also it keeps opening the document.

Can any one tell me wher is the problem?

#target indesign
#targetengine "session"
var myLastDoc;
var myConfirm;
var myCheckSpellEvList = app.menuActions.item("Check Spelling...").addEventListener("beforeInvoke", myCheckSpellHandler, false);
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();
        }
    }
    app.open(myLastDoc);
}
function myCheckSpellHandler(myEvent)
{
    app.activeDocument.insertLabel("SpellingChecked", "true");
}

Regards,

Poo Del

This topic has been closed for replies.

3 replies

Poo_DelAuthor
Known Participant
October 20, 2010

/* 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;
var myCheckSpellEvList = app.menuActions.item("Check Spelling...").addEventListener("beforeInvoke", myCheckSpellHandler, false);
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();
      }
  else
  {
      app.open(myLastDoc);
    }
   }
}
function myCheckSpellHandler(myEvent){
   app.activeDocument.insertLabel("SpellingChecked", "true");
}

I have added else condition to re-open the file. But it gives error that on that line. I trired many times to re-open the file if user is clicking on "No".

Regards,

Poo

Kasyan Servetsky
Legend
October 20, 2010

The afterClose and beforeClose events are very specific: they can run a handler but can't prevent the document from closing. That's why my script does some bizarre acrobatics: If the document has not been spellchecked yet, it asks user if he wants to check spelling -- if he clicks NO, the document is closed, if he clicks YES, the document is closed, reopened and Spell Check menu is invoked. That's how it works (the script in post #1).

Regards,

Kasyan

Poo_DelAuthor
Known Participant
October 20, 2010

Some where I have seen re-opening the document. I want to control the users to closing the files until and unless they have not run the spell check.

Regards,

Poo

mindsteam
Participating Frequently
October 9, 2010

Hello, I guess first I'll ask what you want to accomplish via your script? To verify that the document is spell checked each time before closing?

We have two commercial products which really simplify this, MindSpell and MindSpell Pro.

With MindSpell 1.3 we're adding "spell check" and "suggest" events to the "word" script object. Very easy to have a script iterate all words in your text and check each word.

Even simpler, use Preflight rules with MindSpell Pro. Just open the document, apply the MindSpell Pro profile and generate a preflight report.

Here's a screenshot... With MindSpell Pro 1.1 we're adding suggested words to the 'Fix' text for each misspelled word. It will be in the output of the spelling report as well.

More info here:

http://www.mindsteam.com/products/mindspell/index.html

http://www.mindsteam.com/products/mindspellpro/index.html

The updated versions will be released next week.

Best regards,

Heath Horton

Mindsteam Software

Harbs.
Legend
October 9, 2010

Hi Heath,

Very cool! This is something I requested some time back.

Very nice to see that you included this scripting support!

Best,

Harbs

mindsteam
Participating Frequently
October 10, 2010
No text available
Kasyan Servetsky
Legend
October 7, 2010

What you posted is not the final version of the script.

/* 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;
var myCheckSpellEvList = app.menuActions.item("Check Spelling...").addEventListener("beforeInvoke", myCheckSpellHandler, false);
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");
}

Kasyan

Poo_DelAuthor
Known Participant
October 17, 2010

Dear Kasyan,

It is working fine. What I am looking is if any users try to close the files it should ask for spell check. It doesn't allow users to close the document that means if users are clicking on "NO" then it should re-open the document.

What is happening in this script is if user's are clicking on "NO" then it close the document. Rest of all is fine.

Regards,

Poo