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

Run Spell Check before closing an InDesign file

Explorer ,
Aug 06, 2018 Aug 06, 2018

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

1.6K

Translate

Translate

Report

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 ,
Aug 06, 2018 Aug 06, 2018

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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 ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

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

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

Votes

Translate

Translate

Report

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 ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

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.

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

Votes

Translate

Translate

Report

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 ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

Hi Colin,

I was busy in the last few months, sorry for not responding to your suggestion.

One of my colleague worked on this, though he knows a little bit of JavaScript but he is unaware about 'JavaScript for InDesign'. However, he made some progress and created a code that enables the Spell Check Dialog box to pop-up at the time of closing a file. But the problem with this code is that the file cannot be closed .

Currently, when a user close a file, the Spell-Check dialog box appears. So can the script be updated/modified that if the user clicks on the 'Done' button of the Spell-Check, the file gets close.

OR

Can we add an Alert message which says, "Have you run the Spell-Check", Yes/No. If Yes, then file should close, if No, the Spell-Check dialog should box appear.

Any help would be much appreciated

Thanks,

Masood

-------------------------------

#targetengine "session"

main();

function main(){

var myCloseMenuAction = app.menuActions.item("Close");

var myEventListener = myCloseMenuAction.eventListeners.add("beforeInvoke",myBeforeInvokeHandler, false);

}

function myBeforeInvokeHandler(myEvent){

   var myDoc = app.activeDocument.parent;

      myEvent.preventDefault();

      myEvent.stopPropagation();

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

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

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

}

-------------------------------

Votes

Translate

Translate

Report

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 ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

LATEST

I made some improvements on it, can this be refined.

The script is working fine as needed. The only problem lies here is that it is giving another pop-up after closing the file.

-------------------------------

#targetengine "doSomethingInCase"

app.addEventListener("beforeClose", onClose);

function onClose(myEvent) {

  var result = confirm("Have you run the Spell-Check?", true, "WARNING");

  if (result == true) {

  return

  };

  else (result == false) {

    myEvent.preventDefault();

    myEvent.stopPropagation();

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

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

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

  };

  return;

}

-------------------------------

Votes

Translate

Translate

Report

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