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

JavaScript to set path for additional dictionary

Guest
Jan 10, 2017 Jan 10, 2017

I want to add a new, global spelling dictionary for dozens of users, without having to have each individual user add the dictionary..

So, I am looking for a JavaScript that would do the equivalent of:

Edit --> Preferences --> Spelling, clicking on Dictionary and adding a new dictionary with this specific path:

\\file_server\class_master\sitename\InDesign\Dictionary\Global Dictionary.udc

Any assistance would be greatly appreciated.

TOPICS
Scripting
2.8K
Translate
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

correct answers 1 Correct answer

Guru , Jan 15, 2017 Jan 15, 2017

John,

Your mixing up "Windows" with "javascript on Windows"

When you type a file path in Windows explorer or use the path in VB or one of it's mutations then you can use the 'C:\John' notation.

However, when you use a javascript string to refer to the same file you have to use 'C:\\John' with a double \

This is because the \ symbol in javascript strings has a special meaning (escape) as such if you want it to be treated as a literal \ you need to use 2 of them, the alternative is to use '\x5c' i.e.

...
Translate
LEGEND ,
Jan 10, 2017 Jan 10, 2017

Try this:

var path = "\\file_server\class_master\sitename\InDesign\Dictionary\Global Dictionary.udc"

var var lang = app.languagesWithVendors.itemByName("English: USA");

lang.addDictionaryPath (filePath);

Harbs

Translate
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
Guest
Jan 11, 2017 Jan 11, 2017

Not quite there.

On first try, got error message, "Illegal use of reserved word 'var'"

Determined that was from duplication of "var" at start of second line.

After removing one of the "var" entries on that line, tried again and got error message, "filePath is undefined."

Changed "(filePath") at end of third line to "(path)", tried again and that did not work.

Changed start of first line to "var filePath" and end of third line back to "(filePath)", tried again and got error message, "Cannot add dictionary path."

Here is the current version of the script that resulted in the "Cannot add dictionary path" error:

var filePath = "
brainworks.mindshift\data\bw_class-sci\class_master\SCHURZ\InDesign\Dictionary\GlobalDictionary.udc"

var lang = app.languagesWithVendors.itemByName("English: USA");

lang.addDictionaryPath (filePath);

Translate
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
LEGEND ,
Jan 11, 2017 Jan 11, 2017

Sorry for the typos.

It looks like you need colon notation on Mac for it to work. For example, the following works on my machine:

app.languagesWithVendors.itemByName("English: USA").addDictionaryPath ("Macintosh HD:Users:harbs:Desktop:dictionary.udc");

Translate
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
Guest
Jan 11, 2017 Jan 11, 2017

This is for Windows, not Mac.

Translate
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
LEGEND ,
Jan 11, 2017 Jan 11, 2017

Try importing it manually, and copying the exact path to the script.

Translate
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
Guest
Jan 12, 2017 Jan 12, 2017

I have tried again with the desired dictionary simply in a subfolder of the C drive, not on the file server as ultimately desired, and still get the error, "Cannot add dictionary path"

The JavaScript file right now has only this one line, similar to the one line you showed for your Mac:

app.languagesWithVendors.itemByName("English: USA").addDictionaryPath ("C:\4JohnW\GlobalDictionary.udc");

Translate
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
Guru ,
Jan 12, 2017 Jan 12, 2017

You need to escape your path using \\ or use /.

app.languagesWithVendors.itemByName("English: USA").addDictionaryPath ("C:\\4JohnW\\GlobalDictionary.udc");

app.languagesWithVendors.itemByName("English: USA").addDictionaryPath ("C:/4JohnW/GlobalDictionary.udc");

The / would work on the Mac too.

Translate
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
Guest
Jan 13, 2017 Jan 13, 2017

In Windows, a double slash indicates a server or computer name, such as
myfileserver<file:///
myfileserver>, and a single slash is used for subfolders, such as
myfileserver\shareddrive\subfolder<file:///
myfileserver\shareddrive\subfolder>. There is no slash of any kind before the drive letter of the computer on which the folder resides, thus C:\JohnW.

In fact, if you specify a dictionary manually that is on the C drive, the list of dictionaries in InDesign shows C:\JohnW.

I will try the forward slash in hopes that might make a difference.

Translate
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
Guru ,
Jan 15, 2017 Jan 15, 2017

John,

Your mixing up "Windows" with "javascript on Windows"

When you type a file path in Windows explorer or use the path in VB or one of it's mutations then you can use the 'C:\John' notation.

However, when you use a javascript string to refer to the same file you have to use 'C:\\John' with a double \

This is because the \ symbol in javascript strings has a special meaning (escape) as such if you want it to be treated as a literal \ you need to use 2 of them, the alternative is to use '\x5c' i.e. it's ascii code or '\u005c' it's unicode '\\' is easier.

This is a general all platform rule that does not relate specifically to file paths, nor does it relate specifically will InDesign.

Trevor

Translate
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
Guest
Jan 16, 2017 Jan 16, 2017

Thank you, Trevor. After a little more trial and error, I finally got the path to work as desired, which is to a subfolder of a file server, rather than the local computer.

Translate
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
Guru ,
Jan 16, 2017 Jan 16, 2017
LATEST

Hi John

Can you mark either the answers as correct and helpful.

Thanks

Trevor

Translate
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
Guru ,
Jan 12, 2017 Jan 12, 2017

P.s.

Harbs.​ if you have an answer to  Shared Libraries Example  it would be much appreciated.

TIA

Translate
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