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

How to get the name and the path of the font used in photoshop (not textItem.font)

New Here ,
Apr 24, 2015 Apr 24, 2015

Copy link to clipboard

Copied

I'm trying to get the real name of the font and the path, is there a "easy" way to do it ?

i need to get the font file (*.ttf or *.otf) and copy to the same directory as the psd file, that's why textItem.font doen't work for me.

thanks in advance

TOPICS
Actions and scripting

Views

725

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
Adobe
Community Expert ,
Apr 26, 2015 Apr 26, 2015

Copy link to clipboard

Copied

One can get the fontName and fontPostScriptName but I don’t know how they could be used to immediately identify the actual font file on disk.

I suspect what with the differences of the OS’ and the possible locations of available fonts doing a comprehensive search for the connected files might be quite a hassle.

Have you done a Forum search here and over on ps-scripts.com ?

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
Enthusiast ,
Apr 26, 2015 Apr 26, 2015

Copy link to clipboard

Copied

I would even say what you propose is not allowed/intended behavior of platform fonts. Fonts are very much licensed/DRM-constrained content, i.e. either Apple/Microsoft or the user has a contract on the use of the file (you pay separately for web/app/print use) and redistribution is not permitted even in free fonts. So assuming you want to copy the so it could be distributed with the PSD without careful examination of the terms, you're likely to be on shaky legal ground. I would study if you could for example convert textItems to shapes, etc. to be portable.

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
New Here ,
Apr 27, 2015 Apr 27, 2015

Copy link to clipboard

Copied

Thanks guys for the answers.

The purpose of this, i'm doing a script that export al the psd assets, and the xml for android projects, but when i use a different font, i have to embed it on the project, so that's why i need the file.

And yes i already seach on ps-scripts c.pfaffenbichler .

And we own the fonts we will use so i wont have this kind of problems Matias.

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
Enthusiast ,
Apr 27, 2015 Apr 27, 2015

Copy link to clipboard

Copied

Ok. If it's a known set, could you put them in some known shared location and match file names to fontPostScriptName? I mean seems that font's I've installed have kept original name in \Windows\Fonts, but otherwise there is no correlation with the filename. Also tried copying one file in terminal and got "A required privilege is not held by the client.", so likely not possible to do from script even if you could get the filename.

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
Enthusiast ,
Apr 27, 2015 Apr 27, 2015

Copy link to clipboard

Copied

LATEST

You could try this as it looks as if you are using Windows.

Run the VBS script to create a fontlist file on the desktop.

Then run the javaScript on the PSD document.

It should copy the fonts to the same folder as the document, it will also create a text file with a list of fonts.

It didn't find all the fonts in my test psd maybe because it wasn't in the windows/font folder?

VBS.

Set wshShell = WScript.CreateObject("WScript.Shell")

Set wshSysEnv = wshShell.Environment("PROCESS")

sMyFile = "c:" & wshSysEnv("HOMEPATH") & "\Desktop\Fontlist.txt"

Dim objFileSystem, objOutputFile

Dim strOutputFile

Set objFileSystem = CreateObject("Scripting.fileSystemObject")

Set objOutputFile = objFileSystem.CreateTextFile(sMyFile, TRUE)

Dim str

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _

strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Fonts"

objReg.EnumValues HKEY_LOCAL_MACHINE, _

strKeyPath,arrEntryNames,arrEntryZZZ

For Each entry in arrEntryNames

str = wshshell.RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts\" & entry)

       objOutputFile.WriteLine(entry & "," & str)

Next

objOutputFile.Close

javaScript.

#target photoshop;

app.bringToFront();

main();

function main(){

if(!documents.length) return;

try{

var Path = activeDocument.path;

}catch(e){

    alert("This document needs to be saved before running this script!");

    return;

    }

var FontFile = File(Folder.desktop + "/FontList.txt");

if(!FontFile.exists){

    alert("You need to run the vbs script first to create the FontList file!");

    return;

    }

var FontList = new Array();

    FontFile.open('r') ;

while(!FontFile.eof){  

   strInputLine =FontFile.readln();

   if (strInputLine.length > 3) inputArray  = strInputLine.split(",");

   if(inputArray.length == 2) FontList.push([[inputArray[0]],[inputArray[1]]]);

   }

FontFile.close();

var PSDtextLayers = getNamesPlusIDs();

PSDtextLayers = UniqueSortedList(PSDtextLayers);

for(var a in PSDtextLayers){

    for(var f in FontList){

         var rex = new RegExp;

         rex = PSDtextLayers.toString();

        if(FontList[1].toString().match(rex,"i")){

            var From = new File("/c/windows/fonts/" + FontList[1].toString());

            var To = new File(Path + "/"+  FontList[1].toString());

            From.copy(To);

            break;

            }

        }

    }

var rFonts = new File(Path + "/required Fonts.txt");

rFonts.open('w');

rFonts.write(PSDtextLayers.join('\n'));

rFonts.close();

};

function UniqueSortedList(ArrayName){

var unduped = new Object;

for (var i = 0; i < ArrayName.length; i++) {  

unduped[ArrayName] = ArrayName;

}

var uniques = new Array;for (var k in unduped) {

   uniques.push(unduped);}

return uniques;

}

function getNamesPlusIDs(){

   var ref = new ActionReference();

   ref.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( 'NmbL' ));

   ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

   var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;

   var Names=[];

try{

    activeDocument.backgroundLayer;

var i = 0; }catch(e){ var i = 1; };

   for(i;i<count;i++){

       if(i == 0) continue;

        ref = new ActionReference();

        ref.putIndex( charIDToTypeID( 'Lyr ' ), i );

        var desc = executeActionGet(ref);

        var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));

        var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));

        if(layerName.match(/^<\/Layer group/) ) continue;

        if (desc.hasKey(stringIDToTypeID('textKey'))){

            desc = desc.getObjectValue(stringIDToTypeID('textKey'));

            desc = desc.getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle'));

            var postScriptName = desc.getString( stringIDToTypeID('fontPostScriptName'));     

Names.push(postScriptName);

}

   };

return Names;

};

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