Skip to main content
Known Participant
July 30, 2019
Answered

InDesign dictionary

  • July 30, 2019
  • 2 replies
  • 4513 views

Hi All,

I would need help on display InDesign dictionary Language name of working document through a javascript script. When a user opens a document then script alert that which language currently enabled on InDesign.

Any help on this highly appreciated!

Thanks,

Pramod

This topic has been closed for replies.
Correct answer Sunil Yadav

Hi Sunil,

The script is running through the script panel folder, not the startup script folder.

Can you guide me how can I add scriptmenu action and create the menu button?

Have you tested this script?

Thanks,

Pramod


Try this code:

//==========================================================||

// Created By Sunil Yadav on Dated : 01-08-2019 05:25 PM =====||

//==========================================================||

#targetengine "Dictionary"

try{app.menus[0].submenus.item("Dictionary").remove();}catch(e){}

try{app.scriptMenuActions.item("Dictionary").remove();}catch(e){}

try{app.scriptMenuActions.item("Change Dictionary").remove();}catch(e){}

var subMenu1 = app.menus[0].submenus.add("Dictionary");

var sunilactions = app.scriptMenuActions.item("Change Dictionary");

if(sunilactions == null ) { 

    var sunilactions = app.scriptMenuActions.add("Change Dictionary");

    }

subMenu1.menuItems.add(sunilactions);

var myEventListener = sunilactions.eventListeners.add("onInvoke", function(){

    try{

        if(app.documents.length > 0){

            var myDoc = app.activeDocument;

            var myLanguages = new Array();

            for (j=0;j<app.languagesWithVendors.length;j++){

                myLanguages.push(app.languagesWithVendors.name);

                }

            myDlg = new Window("dialog","Select language");

            myDlg.orientation ="column";

            myDlg.alignment ="right";

            myDlg.DDgroup = myDlg.add("group");

            myDlg.DDgroup.orientation ="row";

            myDlg.DDgroup.add("statictext", undefined,"Languages");

            myDlg.DDgroup.DD = myDlg.DDgroup.add("dropdownlist", undefined, undefined, {items:myLanguages});

            myDlg.DDgroup.DD.selection = 7;

            var buttonGroup = myDlg.add("group");

            buttonGroup.add("button", undefined,"OK");

            buttonGroup.add("button", undefined,"Cancel");

            result = myDlg.show();

            if(result == 1){

                alert(myDlg.DDgroup.DD.selection);

                for (i=0;i<myDoc.paragraphStyles.length;i++){

                    try{myDoc.paragraphStyles.appliedLanguage = app.languagesWithVendors.item(myDlg.DDgroup.DD.selection.index);}

                    catch(e){}

                    }

                for (k=0;k<myDoc.characterStyles.length;k++){

                    try{myDoc.characterStyles.appliedLanguage = app.languagesWithVendors.item(myDlg.DDgroup.DD.selection.index);}

                    catch(e){} 

                    } 

                }

            }

        else alert ("No document is opened!", "Error message", true);

        }

    catch(e){}

}

);

//==========================================================||

//==========================================================||

//==========================================================||

Best

Sunil

2 replies

Sunil Yadav
Legend
August 1, 2019

Hi pramod,

Try this for your reference:

#targetengine "session" 

var myDoc = app.documents[0] ;

//////

function getDictionaryName(){

    var appliedLanguages = [];

    for(var st = 0; st < myDoc.stories.length; st++){

        for(var p = 0; p < myDoc.stories[st].paragraphs.length; p++){

            var lanName = myDoc.stories[st].paragraphs[st].appliedLanguage.name;

            var match = false;

            for(var al = 0; al < appliedLanguages.length; al++){

                if(lanName == appliedLanguages[al]){

                    match = true;

                    break;

                    }

                }

            if(match == false){

                appliedLanguages.push(lanName);

                }

            }

        }

    if(appliedLanguages.length > 1){

        var tmpStr = "This document is using multiple dictionary named : ";

        for(var lt = 0; lt < appliedLanguages.length; lt++){

            if(lt < appliedLanguages.length-1) tmpStr = appliedLanguages[lt]+", "

            }

        alert(tmpStr);

        }

    else if(appliedLanguages.length == 1){

        alert("Currently using "+appliedLanguages[0]+" dictionary!!!");

        }

    }

app.eventListeners.add(Event.AFTER_OPEN, getDictionaryName);  

Best

Sunil

Known Participant
August 1, 2019

Hi Sunil,

Many thanks for this script. I will try it and let you know in case of any concerns.

I have one script regarding this task. But My bed luck I got a few errors and I could not rectify them. I would request to have a look at the below script and try to solve it. Here you can go:-

var myDoc = app.activeDocument;

var myLanguages = new Array();

for (j=0;j<app.languagesWithVendors.length;j++){

myLanguages.push(app.languagesWithVendors.name);

}

myDlg = new Window(‘dialog’, ‘Select language’);

myDlg.orientation = ‘column’;

myDlg.alignment = ‘right’;

//add drop-down

myDlg.DDgroup = myDlg.add(‘group’);

myDlg.DDgroup.orientation = ‘row’;

myDlg.DDgroup.add(‘statictext’, undefined, “Languages”);

myDlg.DDgroup.DD = myDlg.DDgroup.add(‘dropdownlist’, undefined, undefined, {items:myLanguages})

myDlg.DDgroup.DD.selection = 7;

myDlg.closeBtn = myDlg.add(‘button’, undefined, ‘OK’);

// add button functions

myDlg.closeBtn.onClick = function()

{ this.parent.close();

}

result = myDlg.show();

alert(myDlg.DDgroup.DD.selection);

for (i=0;i<myDoc.paragraphStyles.length;i++){

try{

myDoc.paragraphStyles.appliedLanguage = app.languagesWithVendors.item(myDlg.DDgroup.DD.selection.index);

}catch(e){}

}

for (k=0;k<myDoc.characterStyles.length;k++){

try{

myDoc.characterStyles.appliedLanguage = app.languagesWithVendors.item(myDlg.DDgroup.DD.selection.index);

}catch(e){}

}

Thanks,

Pramod

Known Participant
August 1, 2019

Hi Sunil,

I have tried your script. The alert is showing only English: USA dictionary, Although I have selected the English: UK dictionary.

Attached screen grabs for your reference.

Thanks,

Pramod

Loic.Aigon
Legend
August 1, 2019

What did you try ?