Skip to main content
rcraighead
Legend
January 9, 2019
Answered

Select Character and replace font?

  • January 9, 2019
  • 1 reply
  • 2202 views

Another simple script I don't know how to write:

I want to search for a specific character (♥) and change the font to "ZapfDingbatsITC". I've tried to find and change similar scripts but nothing is working for me.

Thanks for any help.

This topic has been closed for replies.
Correct answer pixxxelschubser

Thank you for the example file.

I don't have ZapfDingbatsITC on my computer. That's why I use another font in the script snippets.

At first create a textFrame with one character with your ZapfDingbats - and run this line of code:

alert (app.activeDocument.textFrames[0].textRange.characters[0].textFont);

You will need the exact name later for the next script snippet.

Use the font name for ZapfDingbats in line #10 instead and save this script.

// regards pixxxel schubser

var aDoc = app.activeDocument;

var aTF = aDoc.textFrames[0];

var reg = /\u2665/g;

var res, idx;

while (res = reg.exec(aTF.contents))

{

    idx = res.index;

    aTF.textRange.characters[idx].textFont = app.textFonts.getByName("MS-UIGothic");  // or whatever textFont you want

};

This works for the first text frame in the document (as your example file).

Have fun

1 reply

pixxxelschubser
Community Expert
Community Expert
January 9, 2019

for the beginning: Need to remove some characters in the text in active document

Question: which font (and unicode) does your heart (♥) has in your document?

Maybe do you have an example document for us (+ screenshots before/after for comparison)

rcraighead
Legend
January 10, 2019

pixxxel schubser

Thanks for your interest.

Yes. Heart Unicode is U+2665.

Before/After

Sample File: Dropbox - Sample1.ai

File fonts

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
January 12, 2019

Thank you for the example file.

I don't have ZapfDingbatsITC on my computer. That's why I use another font in the script snippets.

At first create a textFrame with one character with your ZapfDingbats - and run this line of code:

alert (app.activeDocument.textFrames[0].textRange.characters[0].textFont);

You will need the exact name later for the next script snippet.

Use the font name for ZapfDingbats in line #10 instead and save this script.

// regards pixxxel schubser

var aDoc = app.activeDocument;

var aTF = aDoc.textFrames[0];

var reg = /\u2665/g;

var res, idx;

while (res = reg.exec(aTF.contents))

{

    idx = res.index;

    aTF.textRange.characters[idx].textFont = app.textFonts.getByName("MS-UIGothic");  // or whatever textFont you want

};

This works for the first text frame in the document (as your example file).

Have fun