Script doesn't work in InDesign configurator

Post Reply
pfischer
Member
Posts: 44
Joined: Tue May 14, 2013 4:57 pm

Script doesn't work in InDesign configurator

Post by pfischer »

Hello together,
I have another, hopefully easy to solve, problem.

I have generated a script, using the wonderful ChainGREP script by Gregor Fellenz.
https://www.indesignblog.com/2017/02/gr ... atisieren/ (sorry, not in english)

The ChainGREP script allows searches saved in InDesign to be chained and processed as a script saved. The GREP search includes the removal of "Discretionary Hyphen".

The script works fine as a local script in InDesign. However, when I include the script in the InDesign configurator, it does not work. There is no error message in the switch log, the script is "executed successfully". However, the Find+Replace function has not been executed in the result, all "Discretionary Hyphen" are still there.
screen.PNG
screen.PNG (12.44 KiB) Viewed 5146 times
Does anyone have an idea what this could be due to?

Many thanks and best regards,
Peter

Code: Select all

//This script was auto generated by chainGREP.jsx
//chainGREP.jsx is provided by Gregor Fellenz https://www.publishingx.de/
//Download at https://www.publishingx.de/download/chain-grep

main();

function main() {
	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 = 17.0;
	var options = app.findChangeGrepOptions.properties;
	app.findGrepPreferences = NothingEnum.NOTHING;
	app.changeGrepPreferences = NothingEnum.NOTHING;
	// Query [[PxC_bedingten Trennstrich löschen]] -- If you delete this comment you break the update function
	try {
		app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
		app.findGrepPreferences.properties = ({findWhat:"~-"});
		app.changeGrepPreferences.properties = ({});
		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;
};
Media asset and production specialist
Group Communications / System Operations
Phoenix Contact GmbH & Co. KG
www.phoenixcontact.com
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Script doesn't work in InDesign configurator

Post by Padawan »

The rules to write adobe scripts in Switch are documented here:
https://www.enfocus.com/manuals/UserGui ... tions.html

I suspect the script will work if you find all references to

Code: Select all

app.documents[0] 
And replace it with

Code: Select all

$doc
pfischer
Member
Posts: 44
Joined: Tue May 14, 2013 4:57 pm

Re: Script doesn't work in InDesign configurator

Post by pfischer »

Hi Padawan,

thanks for your tip, but unfortunately it does not solve the problem. The script is executed by Switch without error message, but unfortunately without executing the Search+Change function.

Unfortunately, I am at a loss here as to what the problem may be, because locally or manually started, the script runs fine and performs the GREP search in InDesign.

Many greetings,
Peter
Media asset and production specialist
Group Communications / System Operations
Phoenix Contact GmbH & Co. KG
www.phoenixcontact.com
freddyp
Advanced member
Posts: 1023
Joined: Thu Feb 09, 2012 3:53 pm

Re: Script doesn't work in InDesign configurator

Post by freddyp »

Perhaps that in the context of Switch app.layoutWindows.length is equal to 0?

Code: Select all

if (app.layoutWindows.length == 0) return;
In that case nothing happens which is indeed a successful execution of the script from a technical point of view. Or perhaps it is the if statement two lines down? You will have to experiment a little bit.
pfischer
Member
Posts: 44
Joined: Tue May 14, 2013 4:57 pm

Re: Script doesn't work in InDesign configurator

Post by pfischer »

Thank you Freddy,
Your first hint helped me. It was enough to deactivate the line.
After that the script ran without problems in the switch workflow and performed the GREP search.

I will still watch the results to see if it stays error free.

Many thanks and best regards,
Peter
Media asset and production specialist
Group Communications / System Operations
Phoenix Contact GmbH & Co. KG
www.phoenixcontact.com
Post Reply