Skip to main content
Inspiring
June 10, 2019
Answered

How can I get the currently selected font in Photoshop?

  • June 10, 2019
  • 1 reply
  • 1157 views

I would like to let the user choose a font in Photoshop then run a script and get the currently selected font to use with a text layer. How can I get the currently selected font from Photoshop? Thanks.

This topic has been closed for replies.
Correct answer r-bin

var r = new ActionReference();

r.putClass(stringIDToTypeID("typeCreateOrEditTool"));

var d = new ActionDescriptor();

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var font = executeActionGet(r).getObjectValue(stringIDToTypeID("currentToolOptions")).getObjectValue(stringIDToTypeID("textToolCharacterOptions")).getObjectValue(stringIDToTypeID("textStyle")).getString(stringIDToTypeID("fontName")); 

alert(font);

1 reply

r-binCorrect answer
Legend
June 10, 2019

var r = new ActionReference();

r.putClass(stringIDToTypeID("typeCreateOrEditTool"));

var d = new ActionDescriptor();

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var font = executeActionGet(r).getObjectValue(stringIDToTypeID("currentToolOptions")).getObjectValue(stringIDToTypeID("textToolCharacterOptions")).getObjectValue(stringIDToTypeID("textStyle")).getString(stringIDToTypeID("fontName")); 

alert(font);

BazslAuthor
Inspiring
June 10, 2019

Thanks. Two more questions.

1) How can I get the PostScript font name, which I need to set the font in a script.

2) Where can I find information on the properties of the typeCreateOrEditTool object and other PS tools.

Thanks again.

Legend
June 10, 2019

1. Instead of stringIDToTypeID ("fontName") use stringIDToTypeID("fontPostScriptName");

2. I do not know. This is my personal research.