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

Spell Check

New Here ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

Hi Everyone,

I have a spell check script for Indesign to check the spelling in Indesign. But the problem is I have to click on this script to execute it. 

My propose is the artist get a message to check to spell before closing the document.

Is any option that this script active once the artist opens the InDesign file.

Thanks,

Pramod

TOPICS
Scripting

Views

1.8K

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 ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

Hi Pramod,

Look at the following discussion, what you need is an event listener before closing the document

Re: Run Spell Check before closing an InDesign file

-Manan

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
New Here ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

Hi Manan,

I have tried this script earlier. It only runs one time if you put this script to start up folder or click manually to run it.

I need a script that is run automatically once an artist closes the document.

Thanks for your response.

Thanks,

Pramod

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 ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

Try the script given in the following link. it will alert you a confirmation box every time you close a document. Once you get to this point the next point is to put your current code in this script and you should be fine

-Manan

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
New Here ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

Hi Manan,

I have tried this code when I close the document a message came "Have you run the Spell-Check?". If I click on Yes option, document close but if I click on No option. I got an error.

Any help on this will be much appreciated.

Thanks,

Pramod

Spell Check.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 ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

Pramod, the error you are getting is related to some code that you have used to create a menu. Unless we look at the code we can't tell what is going on. But the code snippet that you used to add the event listener seems to be working fine, now you need to debug the code that you added into the event listener

-Manan

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
New Here ,
Jul 15, 2019 Jul 15, 2019

Copy link to clipboard

Copied

Hi Manan,

Hope you're doing good!

Do you have any idea how can I active spell check script when I open the InDesign document for the first time or start the InDesign?

Looking forwarding your answer.

Thanks,

Pramod

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

Copy link to clipboard

Copied

Hi Pramod,

As i mentioned before you have to call your script from within the event handlers that you attach to your document. Since i have not seen the code you have for your spell check i can't comment on why calling it is giving you an error. You can look at the event afteropen to call up your script each time a document is opened in InDesign

-Manan

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
New Here ,
Jul 15, 2019 Jul 15, 2019

Copy link to clipboard

Copied

Hi Manan,

Here is the code for your reference.

"

#targetengine "inDesign"

app.addEventListener("beforeClose", onClose);

function onClose(e) {

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

  if (result == true) {

    app.eventListeners.everyItem().remove();

    return

  }

  else(result == false) {

    e.stopPropagation();

    e.preventDefault();

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

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

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

  }

}

"

I have tried afteropen event but I could not success to get the desired result.

Thanks,

Pramod

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

Copy link to clipboard

Copied

This code works fine for me, and pops up the spell check dialog when i press no on the prompt dialog. I am not sure why you are getting the error, which version of InDesign are you using? Might be possible that your version of InDesign does not have the menu with the name "Check Spelling..." but rather it is present with another name. See if this menu item exists or not. This code will also fail if your are using a non english version of InDesign as it would not have the menu displayed in english, to be safe you should use the menu string as $ID/Check Spelling...

Now the other issues with your code is that when the user clicks on Yes you remove all the eventlisteners added on to the app, do you really need this? This would mean that once the user clicks yes your code would never be called again as you have removed the event listener. In my opinion you should just do nothing in this case. The other issue is that you are blindly removing the event handlers, think of the situation where the app has some handlers added by some other scripts, your code will then break other scripts as well

-Manan

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
New Here ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

Hi Manan,

I'm not getting any error with the code. I want to some more functionality in this script. 

1. This script to be automatically activated once the InDesign open.

2.  The user clicks on Yes, then script asks again to the user to confirm to do not check the spell check.

Thanks,

Pramod

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
Engaged ,
Jul 17, 2019 Jul 17, 2019

Copy link to clipboard

Copied

You didn't say what went wrong with the afterOpen event, but one common problem is that it fires twice when you open a document: The first target will be the document and the second will be the LayoutWindow. If you test for the event.target, you will be able to display your alert only when the LayoutWindow opens. But then, as Manan points out, you can't remove the event listener if you want it to run on every document.

I suggest that you employ two event listeners: The first, attached to the application, listens for the  "afterOpen" event. It tests for the target of the event. If the target is a "LayoutWindow" a "beforeClose" listener is attach to that window.

In this way, you never have to remove either event listener. The afterOpen listener runs throughout your session, attaching beforeClose listeners to all of the LayoutWindows you open. Each beforeClose listener is destroyed when the window closes, but it will already have executed your confirm().

It is possible to add even more functionality to this: FIrst, attach an "afterInvoke" listener to the spell-check menu item. Its function will be to record the date and time in a script label for the document. Then, use the afterOpen listener described above to attach a beforeClose listener to each LayoutWIndow. Rather than ask your designer if he/she has used spellcheck, the beforeClose function will be able to read the script label to find out if spellcheck has been used and, if so, when.

So your confirm message could say things like: "You have not used spell check on this document" or "The last time you spell-checked this document was [time and date from the script label." If you have more than one designer working on the same documents, you should be able to get the userID from the system variables and store that info in the script label too. Then your beforeClose event listener could check to see if the current user has employed spellcheck even if a previous user did it earlier.

Hope this helps,

Bob

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
New Here ,
Jul 19, 2019 Jul 19, 2019

Copy link to clipboard

Copied

Hi Bob,

Thanks for the informative information. I'm afraid that I'm not a hardcore programmer. Therefore I will be a long to make these changes into my script.

It would be much appreciated if you could update the script. I'm very grateful to you.

Looking forward to hearing from you soon.

Have a nice day ahead!

Thanks,

Pramod

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
New Here ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Hi Bob,

Any update on above request.

Thanks,

Pramod

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
Engaged ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Hmmm. Your engagement letter must've gotten lost in the mail...

Rather than try to fix your script, I will offer an example. It's based on a more complicated script I wrote for a client, but it will do what you asked for, and more:

Dropbox - spellCheckMonitor.jsx - Simplify your life

Put this file in the Adobe startup scripts folder. Restart InDesign.

Usage of spell check is tracked by an event listener attached to the menu event. The latest timestamp is stored in an inserted label attached to the document; all timestamps are recorded more permanently in a .csv file saved to the user's desktop. I'd suggest that you change that path to a shared server, especially if you want more than one designer to use it.

When your designer closes a page, he/she will see a prompt displaying the time and date of the last time spell check was invoked. Or a message saying that there is no spell check history. The designer has the option of running spell check at that moment, which keeps the document open. The designer's decision is also recorded in the .csv file

As you may know, .csv can be read as a plain text file or opened in Excel or another spreadsheet application where the data can be filtered and sorted.

Hope this helps,

Bob

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
New Here ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Hi Bob,

Many thanks for sending the script. I will test it and get back to you in case of any help!

Thanks,

Pramod

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
New Here ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Hi Bob,

It is working fine. Many thanks for all your help and efforts.

Thanks,

Pramod

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
New Here ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

Hi Bob,

Sorry, I'm coming back to you!

The script is working fine in PC. My bad luck, we got an error when we tested this script on Mac.

TypeError: null is not an object.

Any help on this much appreciated!

Thanks,

Pramod

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
New Here ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

Hi Bob,

I need your desperate help on this error. This error window pops up when I am running this script.

Thanks,

Pramod

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
Engaged ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

I don't have access to a Mac with a licensed copy of InDesign and so cannot locate the source of the error.

You don't say if the error message appears instead of the spell-check reminder or, perhaps, after it. That's an important detail.

I have updated the script file in Dropbox with the following changes:

1) Each event-listener function is wrapped in a try/catch block. If the error is coming from one of those functions, it will be written to the log file and the log entry will include the line number in the script that is generating the error.

2) The function that writes the script log no longer uses the $.getenv("USERNAME") method to log the name of the current user. This seems to me to be the most likely source of the error. It would be important if you were logging script info to a server from multiple users, but there are other ways to  do that.

Bob

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
New Here ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

Hi Bob,

Thanks for your response. This error appears when this script is running at every moment. i.e., close the document, checking the spell check,  click on "Yes" or "No" options. I will check the updated script and let you know it is running fine on the mac. 

Thanks,

Pramod

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
New Here ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

Hi Bob,

The script this running fine on the Mac. Thanks very much for all your effects and help!

Thanks,

Pramod

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
Engaged ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

This supports my theory that the problem came from the line that attempted to get the user's name from the system variables.

To confirm that, can you run this line from the ESTK on your Mac:

$.getenv("USERNAME");

I think it will throw an error. Or perhaps return null.

If it is important to you, for logging purposes, to know who agreed or refused to run spell-check, then we need to figure out which system variable to reference on the Mac. But you have not said whether the script log is useful to you. My experience is that is is only useful if it can be saved on a shared server, so that you can tell at a glance which designers are using spell-check and which are not.

Bob

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
New Here ,
Jul 29, 2019 Jul 29, 2019

Copy link to clipboard

Copied

Hi Bob,

I will certainly try this line and confirm to you.

Thanks,

Pramod

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
New Here ,
Jul 30, 2019 Jul 30, 2019

Copy link to clipboard

Copied

Hi Bob,

I have tested the line code. I think Windows and Mac have different environmental variables. Therefore, It does not work on the Mac.

Thanks,

Pramod

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