4 Replies Latest reply on May 15, 2017 1:48 AM by phil994

    Access Font Pathname through script

    phil994

      I am currently working on a fully automated script, which exports bulks of photoshop-layers and when encountering a Textlayer, the font file should be automatically copied into the export location aswell.

      A xml file is also generated in which important the layerinformation  be saved, like bounds, transparency as well as fonts, to be able to recreate and know, which layers had which fonts used

       

      My problem now is, it seems it is only possible to access the font information through layer.textItem.font, which doesnt contain the information i am after.

      So for example a textelement uses the font "arial.ttf". The information given by photoshop is "ArialMT", in the actual registry there is no font with this name and for this reason my exporter thoesnt know, which font has to be exported. Same problem with many other fonts, which get "additions" in their name by photoshop. I havent found a way to solve this other than to manually clean up the names, but this doesnt work if the user of the script uses own fonts

       

       

      Is there any way through javascript to access the actual fontname or filename?

       

      Thanks!.

        • 1. Re: Access Font Pathname through script
          JJMack Most Valuable Participant

          dobe Photoshop has a Fonts collection that contains some information about fonts on your system Photoshop can use.  Fonts are installed into your OS.  Windows installs fonts into its folder "C:\Windows\Fonts\" I do not know how Fonts are installed on Mac s.

           

          "ArialMT" seems to be the PostSsciptName for using  getByName gets this information from Photoshop fonts collection.

           

          var myFont = app.fonts.getByName("ArialMT");

          alert("Font family " + myFont.family +"\n"

          + "Font name "  + myFont.name +"\n"

          + "Font parent " + myFont.parent +"\n"

          + "Font postScriptName " + myFont.postScriptName +"\n"

          + "Font style " + myFont.style +"\n"

          + "Font typename " + myFont.typename );

           

           

          Capture.jpg

          Showing more info is widows file explore does not show and file name for that font.

          Capture.jpg

          1 person found this helpful
          • 2. Re: Access Font Pathname through script
            SuperMerlin Level 5

            On Windows you could use vbs to get details...

            This example will write out details to the desktop.

             

            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
            
            
            
            
            
            
            
            
            • 3. Re: Access Font Pathname through script
              Jarda Bereza Level 4

              If you document uses Google fonts, you could maybe download them to you specified filepath.

              They are available on GitHub: GitHub - google/fonts: Font files available from Google Fonts

               

              Every font has metadata file with name and font file-name.

              • 4. Re: Access Font Pathname through script
                phil994 Level 1

                Perfect, thank you.

                Havent thought of that. The getByName function helped me quite a bit.