Skip to main content
israelp20923262
Known Participant
January 4, 2023
Question

Change doubleQuotes using javascript

  • January 4, 2023
  • 2 replies
  • 245 views

Good Morning and Happy new Year.

I'm trying to change the preference of double quotes with javascript, my code is:

 

var languages= activeDoc.languages;
if (languages != null) {
  var language= languages[0];
  language.doubleQuotes = '””'
}

but this code don't run.

Does anyone know how to change this preference?

thank you

This topic has been closed for replies.

2 replies

m1b
Community Expert
Community Expert
January 4, 2023

Hi @israelp20923262, since you are doing scripting, have a look at this snippet:

function main() {

    // select some text, then run script

    var doc = app.activeDocument,
        text = doc.selection[0];

    if (!text.hasOwnProperty('appliedLanguage')) {
        alert('Please select some text and try again.');
        return;
    }

    var lang = doc.languages.itemByName(text.appliedLanguage.name);

    lang.doubleQuotes = "””";

}


app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Language Quotes');

 

I think the key point is how you target the correct language. activeDoc.languages[0] usually means "No Language", so that might be the problem in your case. To make it streamlined, I am just using the selected text to tell us which language is applied, and change the double quotes for that language.

- Mark

Derek Cross
Community Expert
Community Expert
January 4, 2023

 Can't you use Find/Change, once for opening and once for closing quotation marks?