• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

User-installed fonts not picked up by getByName() in jsx

Community Expert ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

I'm trying to access a font via jsx, passing a string. 

If I pass a system font, such as "Helvetica", it works fine. If I pass "Augustine", it fails. 

Getting .name of app.textFonts shows "Helvetica-Regular" and "AugustineRegular". I wonder if that hyphen is an issue. 

Below is the function I'm using: Anyone have any thoughts? Thanks. 

 

var appFont = app.textFonts.getByName(fontString);

 

TOPICS
Scripting

Views

446

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
community guidelines

correct answers 1 Correct answer

Valorous Hero , Jan 15, 2021 Jan 15, 2021

Yes, your new font name is "AugustineRegular" so try passing that in.

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Hi brianp311,

 

Could you try this little test? First select a text frame object and run this script.

 

// 1. get the name of the font from the selected text frame.
var textFrame = app.activeDocument.selection[0];
if (textFrame.typename == 'TextFrame') {
    var actualFontName = textFrame.textRange.characterAttributes.textFont.name;
    try {
        // 2. now try to getByName, using that name
        var theFont = app.textFonts.getByName(actualFontName);
        alert('Getting the font "' + theFont.name + '" worked!');
    } catch (error) {
        alert('Getting the font "' + actualFontName + '" failed!' + error);
    }
}

 

 

Let me know how you go.

- Mark

Votes

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
community guidelines
Community Expert ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

It was happening on a client's machine. It seems the naming was just a bit off for some of the user-installed files. I wrote him a script to get the exact names for what he needs to pass via csv. Thanks for the help. 

Votes

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
community guidelines
Community Expert ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

LATEST

Oops, sorry I realise I misunderstood your question. 🙂

Votes

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
community guidelines
Valorous Hero ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Yes, your new font name is "AugustineRegular" so try passing that in.

Votes

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
community guidelines
Community Expert ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

That did it. Thanks. 

Votes

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
community guidelines