Highlighted

Spell Check

New Here ,
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

650

Likes

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

Spell Check

New Here ,
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

651

Likes

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
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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
Reply
Loading...
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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
Reply
Loading...
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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
Reply
Loading...
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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
Reply
Loading...
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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
Reply
Loading...
Contributor ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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

Copy link to clipboard

Copied

Hi Bob,

Any update on above request.

Thanks,

Pramod

Likes

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
Reply
Loading...
Contributor ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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

Copy link to clipboard

Copied

Hi Bob,

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

Thanks,

Pramod

Likes

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
Reply
Loading...
New Here ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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
Reply
Loading...
Contributor ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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
Reply
Loading...
New Here ,
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

Likes

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
Reply
Loading...
Contributor ,
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

Likes

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

Copy link to clipboard

Copied

Hi Bob,

I will certainly try this line and confirm to you.

Thanks,

Pramod

Likes

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
Reply
Loading...
New Here ,
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

Likes

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

Copy link to clipboard

Copied

Hi Bob,

I would say millions of thanks to you for helping me to create this script possible. I'm seeking last help on this script.

How can display InDesign dictionary Language name through this script? or we can add some code to this script to display the name of the dictionary Language name.

Thanks,

Pramod

Likes

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
Reply
Loading...
Contributor ,
Jul 30, 2019

Copy link to clipboard

Copied

First, I would like to know if the Mac threw an error on

$.getenv("USERNAME");

or did it return null?

I'd also like to know if your Mac has a file called "spellCheckLog.csv" on the desktop after the script runs.If so, it should contain a line pinpointing the error.

Likes

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
Reply
Loading...
Contributor ,
Jul 30, 2019

Copy link to clipboard

Copied

As for the dictionary: In my working environment, we use a third-party spell checker with a custom dictionary, thus I have no experience with scripting the Adobe dictionaries. There are, however, several discussions on this forum about how to address them. It would appear that you can extract the name of the dictionary like this:

app.textDefaults.appliedLanguage.spellingVendor;

Even better, you can extract an array of available dictionaries like this:

app.textDefaults.appliedLanguage.spellingVendorList;

And activate one of them like this:

app.textDefaults.appliedLanguage.spellingVendor=app.textDefaults.appliedLanguage.spellingVendorList;

where n = the desired index in the spellingVendor list

You need to be more clear about what you want to do and when you want to do it. Do your designers have to switch dictionaries? If so, I'd display a list when the page opens so that they can select a dictionary then. This would be especially appropriate if they are using dynamic spellcheck. If not, I wouldn't bother asking them or even telling them what dictionary is active; I'd make sure they were using the one they're supposed to be using. That's probably something that could be done once, in a startup handler.

Bob

Likes

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
Reply
Loading...