Copy link to clipboard
Copied
I am trying to add a working script into a dialog box with a dropdown, but it stops running when it reaches the line app.scriptPreferences.version = 15.1;.
When I run that script on its own or set it up to run from the beginning it works fine, so I don’t really understand why it won’t work in this case. Could someone give me a hand here?
Complete code here:
//Japanese GREP
function JP() {
if (app.layoutWindows.length == 0) return;
var changeObject = app.documents[0];
if (changeObject.hasOwnProperty('characters') && changeObject.characters.length == 0) return;
var doc = app.documents[0];
var style;
var scriptVersion = app.scriptPreferences.version;
app.scriptPreferences.version = 15.1;
var options = app.findChangeGrepOptions.properties;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_black]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Black"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Heavy"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_bold]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Bold"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Bold"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_bolditalic]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Bold Italic"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Bold", skew:11});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_heavy]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Heavy"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Heavy"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_italic]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Italic"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Regular ", skew:11});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_light]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Light"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Light"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_lightitalic]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Light Italic"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Light", skew:11});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_reg]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Regular"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Regular "});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_semib1]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Semi Bold"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Medium"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[JP_semib2]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Semibold"});
app.changeGrepPreferences.properties = ({kinsokuSet:1248357235, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans JP", fontStyle:"Medium"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findChangeGrepOptions.properties = options;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.scriptPreferences.version = scriptVersion;
};
function getStyleByString(docOrGroup, string, property) {
if (string == '[No character style]') return docOrGroup[property][0];
if (string == '[No paragraph style]') return docOrGroup[property][0];
if (string == 'NormalParagraphStyle') return docOrGroup[property][1];
stringResult = string.match (/^(.*?[^\\]):(.*)$/);
var styleName = (stringResult) ? stringResult[1] : string;
styleName = styleName.replace (/\\:/g, ':');
remainingString = (stringResult) ? stringResult[2] : '';
var newProperty = (stringResult) ? property.replace(/s$/, '') + 'Groups' : property;
var styleOrGroup = docOrGroup[newProperty].itemByName(styleName);
if (remainingString.length > 0 && styleOrGroup.isValid) styleOrGroup = getStyleByString (styleOrGroup, remainingString, property);
return styleOrGroup;
};
// KO GREP
function KO() {
alert(languages.selection)
if (app.layoutWindows.length == 0) return;
var changeObject = app.documents[0];
if (changeObject.hasOwnProperty('characters') && changeObject.characters.length == 0) return;
var doc = app.documents[0];
var style;
var scriptVersion = app.scriptPreferences.version;
app.scriptPreferences.version = 15.1;
var options = app.findChangeGrepOptions.properties;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_black]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Black"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Heavy"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_bold]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Bold"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Bold"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_bolditalic]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Bold Italic"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Bold", skew:11});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_heavy]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Heavy"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Heavy"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_italic]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Italic"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Regular ", skew:11});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_light]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Light"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Light"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_lightitalic]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Light Italic"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Light", skew:11});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_reg]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Regular"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Regular "});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_semib1]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Semi Bold"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Medium"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// Query [[KO_semib2]] -- If you delete this comment you break the update function
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"[^.,;:?!-()%&\\[\\]\\d a-z|A-Z]+", fontStyle:"Semibold"});
app.changeGrepPreferences.properties = ({kinsokuSet:1263692659, composer:"Adobe Japanese Paragraph Composer", appliedFont:"Source Han Sans KR", fontStyle:"Medium"});
changeObject.changeGrep();
} catch (e) {alert(e + ' at line ' + e.line)}
app.findChangeGrepOptions.properties = options;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.scriptPreferences.version = scriptVersion;
};
function getStyleByString(docOrGroup, string, property) {
if (string == '[No character style]') return docOrGroup[property][0];
if (string == '[No paragraph style]') return docOrGroup[property][0];
if (string == 'NormalParagraphStyle') return docOrGroup[property][1];
stringResult = string.match (/^(.*?[^\\]):(.*)$/);
var styleName = (stringResult) ? stringResult[1] : string;
styleName = styleName.replace (/\\:/g, ':');
remainingString = (stringResult) ? stringResult[2] : '';
var newProperty = (stringResult) ? property.replace(/s$/, '') + 'Groups' : property;
var styleOrGroup = docOrGroup[newProperty].itemByName(styleName);
if (remainingString.length > 0 && styleOrGroup.isValid) styleOrGroup = getStyleByString (styleOrGroup, remainingString, property);
return styleOrGroup;
};
//---------------
/*
Code for Import https://scriptui.joonas.me — (Triple click to select):
{"activeId":5,"items":{"item-0":{"id":0,"type":"Dialog","parentId":false,"style":{"enabled":true,"varName":null,"windowType":"Dialog","creationProps":{"su1PanelCoordinates":false,"maximizeButton":false,"minimizeButton":false,"independent":false,"closeButton":true,"borderless":false,"resizeable":false},"text":"Asian font replacement","preferredSize":[0,0],"margins":16,"orientation":"column","spacing":10,"alignChildren":["center","top"]}},"item-1":{"id":1,"type":"Group","parentId":0,"style":{"enabled":true,"varName":null,"preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["left","center"],"alignment":null}},"item-2":{"id":2,"type":"StaticText","parentId":1,"style":{"enabled":true,"varName":null,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"softWrap":false,"text":"Select the language","justify":"left","preferredSize":[0,0],"alignment":null,"helpTip":null}},"item-4":{"id":4,"type":"DropDownList","parentId":1,"style":{"enabled":true,"varName":"languages","text":"DropDownList","listItems":"Japanese, -, Simplified Chinese, -, Traditional Chinese, -, Korean, -, Thai ","preferredSize":[88,0],"alignment":null,"selection":0,"helpTip":null}},"item-5":{"id":5,"type":"Button","parentId":7,"style":{"enabled":true,"varName":null,"text":"Run","justify":"center","preferredSize":[0,0],"alignment":"right","helpTip":null}},"item-6":{"id":6,"type":"Button","parentId":7,"style":{"enabled":true,"varName":null,"text":"Cancel","justify":"left","preferredSize":[0,0],"alignment":"left","helpTip":null}},"item-7":{"id":7,"type":"Group","parentId":0,"style":{"enabled":true,"varName":null,"preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["left","center"],"alignment":null}}},"order":[0,1,2,4,7,6,5],"settings":{"importJSON":true,"indentSize":false,"cepExport":false,"includeCSSJS":true,"showDialog":true,"functionWrapper":false,"afterEffectsDockable":false,"itemReferenceList":"None"}}
*/
// DIALOG
// ======
var dialog = new Window("dialog");
dialog.text = "Asian font replacement";
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"});
group1.orientation = "row";
group1.alignChildren = ["left","center"];
group1.spacing = 10;
group1.margins = 0;
var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"});
statictext1.text = "Select the language";
var languages_array = ["-","Japanese","Simplified Chinese","Traditional Chinese","Korean","Thai"];
var languages = group1.add("dropdownlist", undefined, undefined, {name: "languages", items: languages_array});
languages.selection = 0;
languages.preferredSize.width = 88;
// GROUP2
// ======
var group2 = dialog.add("group", undefined, {name: "group2"});
group2.orientation = "row";
group2.alignChildren = ["left","center"];
group2.spacing = 10;
group2.margins = 0;
var Closebutton = group2.add("button", undefined, undefined, {name: "Closebutton"});
Closebutton.text = "Cancel";
Closebutton.justify = "left";
Closebutton.alignment = ["left","top"];
var Runbutton = group2.add("button", undefined, undefined, {name: "Runbutton"});
Runbutton.text = "Run";
Runbutton.alignment = ["left","bottom"];
Runbutton.onClick = function(){
dialog.close();
if (languages.selection == "1")
{
JP();
}
else if (languages.selection == "4")
{
KO();
}
};
dialog.show();
Copy link to clipboard
Copied
There is no version 15.1. We are still in version 15.0. That probably has something to do with it. Edit: I stand corrected.
Copy link to clipboard
Copied
Hi together,
the value is a string, not a number.
You could test this like that:
app.scriptPreferences.version.constructor.name // Result:String
So, if you are on InDesign 2020 version 15.1.0.25 it returns:
app.scriptPreferences.version // Returns String: 15.1
And if you want to apply that string, do like this:
app.scriptPreferences.version = "15.1";
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thank you Uwe,
your options made the script pass that point, but now it gets stuck between
var options = app.findChangeGrepOptions.properties;
and
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
I'm new to scripting, and I created this script with another one that creates scripts from saved GREP queries. I have tried to understand why this is happening, but I think I am not there yet...