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

Adobe Community Professional ,
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

74

Likes

Translate

Translate

Report

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

1 Correct Answer

Adobe Community Professional , Jan 15, 2021
Silly-V Adobe Community Professional , Jan 15, 2021
Yes, your new font name is "AugustineRegular" so try passing that in.

Likes

Translate

Translate
Jump to answer Jump to answer
Engaged ,
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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
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. 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
m1b LATEST
Engaged ,
Jan 19, 2021

Copy link to clipboard

Copied

Oops, sorry I realise I misunderstood your question. 🙂

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

That did it. Thanks. 

Likes

Translate

Translate

Report

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