Highlighted

FindChangeByList—local formatting to a character style

Adobe Community Professional ,
Oct 18, 2018

Copy link to clipboard

Copied

I'm back.

I'm making progress—thanks winterm​ and [Jongware]​—but am stuck again. This time I am trying to target local formatting from a Word doc (italics and small caps) and change it to my existing Italic (and eventually SmallCaps) character style(s).

Seems like it might be something like this, but that's not working. No error message, just ignored. Any thoughts?

grep {findWhat:".",fontStyle:"Italic"} {changeTo:"$0",appliedCharacterStyle:"Italic"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Notes: I have the style called Italic (not in a folder) and the text I'm looking for is Italic (not Oblique or some other variation):

Screenshot 2018-10-18 17.25.27.png

TIA,

~Barb

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Hi Barb,

Works for me, one pointer please replace the space with tab after grep and also after }. I noticed that copying and pasting from the forum replaces tab with another character and hence the code does not work. See the instructions in the FindChangeList.txt file for details, i am pasting the relevant line below

findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description

Let me know if it works.

-Manan

TOPICS
Scripting

Views

2.0K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

FindChangeByList—local formatting to a character style

Adobe Community Professional ,
Oct 18, 2018

Copy link to clipboard

Copied

I'm back.

I'm making progress—thanks winterm​ and [Jongware]​—but am stuck again. This time I am trying to target local formatting from a Word doc (italics and small caps) and change it to my existing Italic (and eventually SmallCaps) character style(s).

Seems like it might be something like this, but that's not working. No error message, just ignored. Any thoughts?

grep {findWhat:".",fontStyle:"Italic"} {changeTo:"$0",appliedCharacterStyle:"Italic"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Notes: I have the style called Italic (not in a folder) and the text I'm looking for is Italic (not Oblique or some other variation):

Screenshot 2018-10-18 17.25.27.png

TIA,

~Barb

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Hi Barb,

Works for me, one pointer please replace the space with tab after grep and also after }. I noticed that copying and pasting from the forum replaces tab with another character and hence the code does not work. See the instructions in the FindChangeList.txt file for details, i am pasting the relevant line below

findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description

Let me know if it works.

-Manan

TOPICS
Scripting

Views

2.0K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 18, 2018 0
Adobe Community Professional ,
Oct 18, 2018

Copy link to clipboard

Copied

I have a bunch of these to work through. Is there a resource somewhere with examples of the various options? For my next one I'll need to find a tab, replace with an en space and assign a para style that is contained within a folder. I have the first part working but have no idea how to reference a style contained within a folder.

~Barb

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 18, 2018 0
Adobe Community Professional ,
Oct 18, 2018

Copy link to clipboard

Copied

Regarding using style present in the folders with FindChangeByList.jsx, the issue is that styles within folder can't be accessed directly using its name as done by this script code

So we will have to send something more that just the style name to the FindChangeByList.jsx in order for the code to get the correct style. If we take the original sample and suppose that the character style was within a folder, then the string argument for the script would be something as below

grep {fontStyle:"Italic"} {appliedCharacterStyle:app.doScript('function getStyle(){var cs = app.activeDocument.allCharacterStyles;for(var i = 0; i < cs.length; i++){if( cs[i].name == "Italic" ) return cs[i]}}getStyle()', ScriptLanguage.javascript)} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

For finding the paragraphstyles within folders use the following string

grep {fontStyle:"Italic"} {appliedParagraphStyle:app.doScript('function getStyle(){var ps = app.activeDocument.allParagraphStyles;for(var i = 0; i < ps.length; i++){if( ps[i].name == "Italic" ) return ps[i]}}getStyle()', ScriptLanguage.javascript)} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

P.S. :- In the above string change the name of the paragraphStyle or characterstyle to be found in the line cs[i].name == "Name of CStyle you want to search" and similarly ps[i].name == "Name of PStyle you want to search"

 

Hope this helps, this is my take to the solution, would like to know if someone has any other less complex way of achieving this.

 

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 18, 2018 1
Adobe Community Professional ,
Oct 18, 2018

Copy link to clipboard

Copied

Hi Barb,

You could use the following string

grep {fontStyle:"Italic"} {appliedCharacterStyle:"Italic"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 18, 2018 1
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Hi Manan Joshi:

First of all, thank you for helping.

However, it's still not working. After running the script with just your line, the character style still isn't getting applied.

Screenshot 2018-10-19 06.53.22.png

  And separately, are the words "findWhat:" and "changeTo:" optional when simply doing a format find/change?

~Barb

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 0
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Hi Barb,

Works for me, one pointer please replace the space with tab after grep and also after }. I noticed that copying and pasting from the forum replaces tab with another character and hence the code does not work. See the instructions in the FindChangeList.txt file for details, i am pasting the relevant line below

findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description

Let me know if it works.

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 1
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Yes, that was it, and again, this is documented in the file at the top. I feel like such a numbskull.

On to the paragraph style application with the tab/en dash switch... I'll be back with an update.

THANK YOU, Manan Joshi!

~Barb

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 0
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Hi Manan:

I think I have worked through one of each of the types of strings I need and can probably take it from here. I do have one last (hopefully) easy question on the same topic

Just like the find local italics and replace with my character style called Italic, I'll need to locate and update small caps and superscript text. Using the string you provided above, how do I reference the fontStyle for each? Is this correct? (Because of course neither one is working, and I did remember the tabs.)

{fontStyle:"Smallcaps"}

{fontStyle:"Superscript"}

~Barb

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 0
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Hi Barb,

These are not fontStyles, you can try the following

{position : Position.SUPERSCRIPT}

{capitalization : Capitalization.SMALL_CAPS}

Let me know if it does not work, have not tested it fully.

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 1
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Yes, and yes! So how do you know all this? Is there a good online reference I can review? I can't seem to make any leaps in logic on my own.

Now working on removing small caps applied to digits.

grep     {findWhat:"\\d+", appliedCharacterStyle:"Small Caps"}     {appliedCharacterStyle:"None"}     {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Which of course, does not work.

~Barb

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 0
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Its a bit involved, its basically scripting InDesign and you will need to browse the Object model to get the options. I will try to explain it as best as i can trying not to confuse you.

So for find options in Grep you can look for options at

Adobe InDesign CS6 (8.0) Object Model JS: FindGrepPreference

Similarly for change options in Grep you can look for options at

Adobe InDesign CS6 (8.0) Object Model JS: ChangeGrepPreference

For every option you will also see the type of values that it takes and if it is a special value you can get the relevant values by clicking on the hyperlink, like i gave you the values for position and capitalization options

Similarly for text find options look at

Adobe InDesign CS6 (8.0) Object Model JS: FindTextPreference

And for text change options it is

Adobe InDesign CS6 (8.0) Object Model JS: ChangeTextPreference

I hope this did not create confusion and did add some value to your understanding. If you want to search for glyphs and objects  similar objects exist for them as well. So in a nutshell the FindChangeByList.jsx does nothing but takes the values for these options and executes it.

And now i would like you to try and solve the current problem you have, by using the newly found tricks that are mentioned above. Let me know how it goes.

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 1
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Again, thank you so much. I'm on to laying out a document now but will cycle back to this and let you know if I can solve this final piece on my own.

~Barb

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 0
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Of course I couldn't wait.

Ok, so I can now succesfully change my digits from one character style to another (in this example, Small Caps to Superscript):

grep     {findWhat:"(\\d+)", appliedCharacterStyle:"Small Caps"}     {changeTo:"$1",appliedCharacterStyle:"Superscript"}            {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

This means the first part of the string is correct, right? But changing it from Small Caps to None continues to elude me.

grep     {findWhat:"(\\d+)", appliedCharacterStyle:"Small Caps"}     {changeTo:"$1",appliedCharacterStyle:""}            {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

~Barb

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 0
Adobe Community Professional ,
Oct 19, 2018

Copy link to clipboard

Copied

Use the value "[No paragraph style]" for applying no paragraph style and the value "[No character style]" for applying None as character style.

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 19, 2018 1
Adobe Community Professional ,
Oct 20, 2018

Copy link to clipboard

Copied

Hi Manan:

That was it, and between your answers and [Jongware]'s reference, I was able to complete my list.

I've used inDesign daily since it was released, and while I knew about FindChangeByList, I never took the time to figure out how to use it. Instead, I would run a lengthy series of saved sequential Find/Change queries. I came back from Adobe MAX inspired to update my templates and streamline my workflow.

With your help, the layout for one of my longer documents is nothing less than magical and I've learned so much.

Again, thank you!

~Barb

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 20, 2018 2
Adobe Community Professional ,
Oct 20, 2018

Copy link to clipboard

Copied

Hi Barb,

just to complete the list of DOM documentation references:

For InDesign CC 2019 Gregor Fellenz compiled this one:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

Others also by Gregor can be found here:

https://www.indesignjs.de/extendscriptAPI/

Cheers,
Uwe

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 20, 2018 1
Adobe Community Professional ,
Oct 20, 2018

Copy link to clipboard

Copied

Thanks, Uwe!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 20, 2018 0
Explorer ,
Jun 17, 2019

Copy link to clipboard

Copied

I was looking for some documentation on the correct structure of the grep string within the .txt file used by FindChangeByList to target character styles and paragrahstyles and I end up in this thread. Seems to me Manan has it all sorted out .

Perhaps BarbBinder​ you can enlighten me as well on this...

How can I target a used character style and change that to another? So not targeting a specific string, but specific styles...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2019 0
Adobe Community Professional ,
Jun 17, 2019

Copy link to clipboard

Copied

Hi Peter,

You can look at my comments above for full description, however its very simple. For example if you need to change the character style named "Original" to "Italic" in your document you need to use the following string

grep {appliedCharacterStyle:"Original"} {appliedCharacterStyle:"Italic"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

The first string inside the {} after grep identifies the properties to be searched and the next one identifies the properties to be applied once the search matches. You can look at the full list of properties you can use by referring the following links

Find properties for Grep (the ones you would use to search as explained above)

Adobe InDesign CS6 (8.0) Object Model JS: FindGrepPreference

Replace properties for Grep

Adobe InDesign CS6 (8.0) Object Model JS: ChangeGrepPreference

The other thing that i explained in the above posts was the case of using the character styles and paragraph styles which are present in folders. Since such styles can't be accessed directly by their names in the script, we would need to pass in some JS code in the find/change string and that is what i have done

Hope this helps you to understand and get your task done

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2019 1
Explorer ,
Jun 17, 2019

Copy link to clipboard

Copied

Hi Manan, thanks for chiming in. Unfortunately when I use the mentioned code it is not working; the already applied style is not changed to the new one. This is what I have put in the FindChangeList.txt:

grep  {appliedCharacterStyle:"Italic"} {appliedCharacterStyle:"[No character style]"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

I used tabs between the } { characters.

When I combine a find and replace with the applied style like Barb did, like this line of code:

grep  {findWhat:"\\s~_\\s", appliedCharacterStyle:"Italic"} {changeTo:"~_", appliedCharacterStyle:"[No character style]"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

I get an Javascript error stating "Expected: } (...) Source: app.doScript(myString, ScriptLanguage.javascript);

- but I did not change that piece of code.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2019 0
Adobe Community Professional ,
Jun 17, 2019

Copy link to clipboard

Copied

Hi Peter,

I was able to successfully use your first string and the change did happen, mind that you need to separate each field with a tab so there has to be a tab between grep and { as well. The string should be something like the following

grep<tab>{appliedCharacterStyle:"Italic"}<tab>{appliedCharacterStyle:"[No character style]"}<tab>{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Also with regards to the second string i did not get any error.

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2019 0
Adobe Community Professional ,
Jun 17, 2019

Copy link to clipboard

Copied

Hi Peter,

is any of your character styles used with the list in a character style group?

Regards,
Uwe

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 17, 2019 0
Explorer ,
Jun 18, 2019

Copy link to clipboard

Copied

Hi Uwe,

no, the character styles are not in a group - but when they were the code should be somewhat more complicated, right?

Manan Joshi​ for me the code in the .txt file is not working... I don't know why. I have ID 14.0.2. I created a blank doc and created two character styles: "italic" and "bold". Then I used your .txt example to strip these styles. But to no avail... I wrote a script to strip styles and that's working so I use that instead, although I really do find it frustrating not being able to strip styles using the already provided script by Adobe...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 18, 2019 0
Adobe Community Professional ,
Jun 18, 2019

Copy link to clipboard

Copied

Hi peteremil,

Its difficult to identify issue this way, if possible share the InDesign document with the findchange.txt file and we can see what the issue is.

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 18, 2019 0
Explorer ,
Jun 19, 2019

Copy link to clipboard

Copied

You are totally right Manan Joshi​, I'll see how I can upload my files. This is the first time for me so I'll have to get myself acquainted with the forum ins & outs

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2019 0
Adobe Community Professional ,
Jun 19, 2019

Copy link to clipboard

Copied

Forum does not have any facility to upload files other than images. You could upload the files to a cloud hosting service like Dropbox and post the public link here.

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2019 0
Explorer ,
Jun 19, 2019

Copy link to clipboard

Copied

Here are the links to the .txt and .indd files:

Dropbox - styletest.indd - Simplify your life

Dropbox - FindChangeList.txt - Simplify your life

I think I found the culprit - the tabs seemed not te be inserted correctly.

Is it possible to remove not wanted styles from the InDesign document with FindChangeByList as well?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2019 0
Explorer ,
Aug 14, 2019

Copy link to clipboard

Copied

Hi Manan Joshi​ after some successful find & replace actions I am stuck... like BarbBinder​ said it is difficult to make any leaps in logic on my own. This is the problem I am facing now: I need to target forced returns after a string with the character style "bold"; they need to be replaced by a normal return AND the character style on the string before the return needs to be cleared. The code I have so far doesn't work completely right. The wildcard in the findWhat works but the wildcard in the changeTo replaces the text... how can I accomplish the task in one grep function?  Do I need to work with the "followed by" (?=\n) code or is there a "preceded by" code?

My code so for:

grep {findWhat:".+\n", appliedCharacterStyle:"Bold"} {changeTo:".+\r", appliedCharacterStyle:"[No character style]"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

The text source:

This is a subheading in bold[forced return]

This is a paragraph with some text following the subheading ...

The text result:

This is a subheading without characterstyle[normal return]

This is a paragraph with some text following the subheading ...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 14, 2019 0
Adobe Community Professional ,
Aug 15, 2019

Copy link to clipboard

Copied

Hi peteremil,

I see two issues in your string, mostly its fine

  • Firstly you will have to escape \r and \n so that should be \\r and \\n
  • In findwhat you will have to capture the string before forced enter and then we can use substitution in the changeTo field

So the findWhat should be "(.+)\\n" and changeTo should be "$1\\r"

Here () creates a capturing group that will populate the substitution $1 which means content of the first capturing group.

Try this and let me know if it works or not

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 15, 2019 1
Explorer ,
Aug 15, 2019

Copy link to clipboard

Copied

Thanks a lot Manan Joshi​! You certainly have a lot of grep knowledge. Using your guidance it worked!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 15, 2019 2
Adobe Community Professional ,
Aug 15, 2019

Copy link to clipboard

Copied

I agree!

~Barb

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 15, 2019 1
Explorer ,
Mar 21, 2020

Copy link to clipboard

Copied

I needed similar script, but in JavaScript, therefore I have created the following. It still has an issue: when there is more than one style applied to text, only one style is kept (the one that is issues sooner). I am not a great scripter, therefore If one knows a better algorithm to check all styles in one go, create a necessary character styles and apply the style to the text, I wish to hear about it!

 

// Replace all font style italic with character style Italic

// author:  Tukusej's Sirs
// date:    21 March 2020
// licence: GPLv3


var doc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;

// Replace the following font styles with respective character styles
restyle('Semibold Italic');
restyle('Bold Italic');
restyle('Bold');
restyle('Italic');
restyle('Semibold');
restyle('Small Caps');
restyle('All Caps');
restyle('Superscript');
restyle('Subscript');
restyle('Underline');
restyle('Strikethrough');

function restyle(style) {
	var charStyle = app.activeDocument.characterStyles.itemByName(style);

	// Create `style` character style if missing
	if (! charStyle.isValid) {
		var newStyle = app.documents[0].characterStyles.add();
		newStyle.name = style;

		switch(style) {
			case 'Underline':
				newStyle.underline = true;
				break;
			case 'Strikethrough':
				newStyle.strikeThru = true;
				break;
			case 'Small Caps':
				newStyle.capitalization = Capitalization.SMALL_CAPS;
				break;
			case 'All Caps':
				newStyle.capitalization = Capitalization.ALL_CAPS;
				break;
			case 'Superscript':
				newStyle.position = Position.SUPERSCRIPT;
				break;
			case 'Subscript':
				newStyle.position = Position.SUBSCRIPT;
				break;
			default:
				newStyle.fontStyle = style;
		}

		charStyle = app.activeDocument.characterStyles.itemByName(style);
	}

	// Restyle to character style
	switch(style) {
		case 'Underline':
			app.findGrepPreferences.underline = true;
			break;
		case 'Strikethrough':
			app.findGrepPreferences.strikeThru = true;
			break;
		case 'Small Caps':
			app.findGrepPreferences.capitalization = Capitalization.SMALL_CAPS;
			break;
		case 'All Caps':
			app.findGrepPreferences.capitalization = Capitalization.ALL_CAPS;
			break;
		case 'Superscript':
			app.findGrepPreferences.position = Position.SUPERSCRIPT;
			break;
		case 'Subscript':
			app.findGrepPreferences.position = Position.SUBSCRIPT;
			break;
		default:
			app.findGrepPreferences.fontStyle = style;
	}

	app.changeGrepPreferences.appliedCharacterStyle = charStyle;
	app.changeGrep();
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 21, 2020 0
Participant ,
Apr 15, 2020

Copy link to clipboard

Copied

About the Paragraph Style inside a group it didn't work the way it's here, but I've made a small change at the script and now it's working perfectly for me. 🙂

 

The way it's working is like this:

grep	{fontStyle:"Italic"}	{appliedParagraphStyle:app.doScript('function getStyle() { var ps = app.activeDocument.allParagraphStyles; for(var i = 0; i < ps.length; i++) { if( ps[i].name == "Italic" ) { return ps[i]; } } } getStyle();', ScriptLanguage.javascript)}	{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 15, 2020 0