Skip to main content
Bedazzled532
Inspiring
July 7, 2024
Answered

Tracking/Kerning using grep in script

  • July 7, 2024
  • 1 reply
  • 866 views

Hi

I want to give a tracking value of 100 after an opening paranthesis and before closing paranthesis but I want to do this using a script.

 

I already have a grep query in place for after opening parenthesis: (\x{0028})(?=\S)  and replace is empty. Just add tracking value of 100. If its possible to add kerning value, it will be very good.

 

The grep query for closing parenthesis: (\x{0029})(?=\s) but there the tracking is not working as expected. It is increasing tracking after the closing parenthesis, I want tracking before closing parenthesis.

 

My first preference would be using kerning. I already have Peter's script in place, which works just fine.

Actually I need this because I want to include it in another script.

 

I have come up with this :

doc = app.activeDocument;

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = '(\x{0028})(?=\S)';
app.changeGrepPreferences.changeTo = "how to add tracking/kerning here";
doc.changeGrep();

 

How can I include this in a script?

Thanks

This topic has been closed for replies.
Correct answer Peter Kahrel

Your code works fine, the kerning is applied at the correct places. You could simplify the search strings a bit as follows:

"\\(\\K(?=\\S)"
"\\w(?=\\))"

but your code works as it is.

1 reply

Bedazzled532
Inspiring
July 7, 2024

Ok I have comeup with this:

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(\\x{0028})(?=\\S)";
app.changeGrepPreferences.tracking=200;
app.activeDocument.changeGrep();

How to solve the space not coming before closing parenthesis ?

Bedazzled532
Inspiring
July 7, 2024

Ok, I found the solution.

 

Here is my final code:

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?<=(\\x{0028}))(?=\\S)";
app.changeGrepPreferences.kerningValue=100;
app.activeDocument.changeGrep();

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?<=\\w)(?=\\x{0029})";
app.changeGrepPreferences.kerningValue=100;
app.activeDocument.changeGrep();

 

How can I make it better ?

Thanks

rob day
Community Expert
Community Expert
July 7, 2024

Hi @Bedazzled532 , Specific kerning values need to be applied to an insertionPoint. I can't post any code at the moment, but you should be able to get the insertionPoint after the closed parenthesis and set an amount.

 

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