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

Change doubleQuotes using javascript

Explorer ,
Jan 04, 2023 Jan 04, 2023

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

TOPICS
Scripting , SDK
193
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
Community Expert ,
Jan 04, 2023 Jan 04, 2023

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

Screenshot 2023-01-04 at 10.20.30.pngexpand image

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
Community Expert ,
Jan 04, 2023 Jan 04, 2023
LATEST

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

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