# How to get and set the font?

**URL:** https://forums.creativeclouddeveloper.com/t/how-to-get-and-set-the-font/10216
**Category:** UXP Plugin API
**Tags:** uxp, javascript
**Created:** [March 10, 2025, 2:03pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-and-set-the-font/10216 "2025-03-10T14:03:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![amide](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@amide](https://forums.creativeclouddeveloper.com/u/amide)
#### Post date: [March 10, 2025, 2:03pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-and-set-the-font/10216/1 "2025-03-10T14:03:17Z")

</div>

If I try to get the font of the current text layer through the .psjs file, the code I wrote below is incorrect for some reason. How can I set the font of the current text layer to: DOUYINSANSBOLD-GB?

```auto
const { app } = require("photoshop");
async function getSelectedTextLayerFont() {
    try {
        let font = app.activeDocument.activeLayer.textItem.font;
        await app.showAlert(`Font: ${font}`);
    } catch (error) {
        await app.showAlert(`Error: ${error.message}`);
    }
}
getSelectedTextLayerFont();

```

---

<div class="post-metadata">

### Author: ![jduncan](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jduncan/32/4301_2.png) [@jduncan](https://forums.creativeclouddeveloper.com/u/jduncan)
#### Post date: [March 10, 2025, 3:44pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-and-set-the-font/10216/2 "2025-03-10T15:44:37Z")

</div>

Try this out. There are some edge cases you’ll need to address in a complete solution but this should get you headed in the right direction.

```javascript
const { app } = require("photoshop");

//check for an active document
const doc = app.activeDocument;
if (!doc) {
    app.showAlert("No active documents.");
    return;
}

// get the **first** selected layer
const layer = doc.activeLayers[0];

// update the layer to use the target font
targetFontPostScriptName = "ArialMT";
try {
    layer.textItem.characterStyle.font = targetFontPostScriptName; //
} catch (error) {
    app.showAlert(error);
}

// If you are unsure of the PostScript name of the font you want to use
// here is a little helper function that will show all fonts whose name includes
// the string argument you supply to the function.

/**
 * Log the PostScript names of any fonts whose name includes `s`.
 * @param s String to search for inside of a font name.
 */
function logMatchingFonts(searchString) {
    const matches = app.fonts
        .filter((font) => font.name.toLowerCase().includes(searchString.toLowerCase()))
        .map((font) => font.postScriptName);

    app.showAlert(`Found ${matches.length} matches:\n\n${matches.join("\n")}`);
}

// logMatchingFonts("arial");

```

---

<div class="post-metadata">

### Author: ![amide](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@amide](https://forums.creativeclouddeveloper.com/u/amide)
#### Post date: [March 11, 2025, 12:32am UTC](https://forums.creativeclouddeveloper.com/t/how-to-get-and-set-the-font/10216/3 "2025-03-11T00:32:26Z")

</div>

Thank you for guiding me in the right direction, thank you.
