0 Replies Latest reply on Sep 7, 2015 1:30 PM by ivans25859921

    copy fonts associated with photoshop using jsx

    ivans25859921

      Hi everyone!
      What I want to do is to copy a font associated with current text layer (font name) in some other directory. The main issue I have run to is that app.activeDocument.activeLayer.fonts[i] is an 'internal' name consisted from words concatenated with dashes or pascal cased (like so: MyriadPro-Bold), but real font names (name of the file) is different (like so: mriamc.ttf) it's just a magic abbreviation. Here's what i tried to do:

      The main idea is that I was figuring out what's the font-name of a current layer and then searched through all of the font files in a system directory on windows. And those who was catched - then save in some directory.  But this approach has downside since the name of a font not always be the same as the exact name of a file as I mentioned above. Any ideas or tips would be greatly appreciated!

      function copyFonts () {

          var inputFolder,

              folderContent,

              currentFile,

              defaultExportFolder,

              destFile,

              fontName,

              i;

       

          fontName = app.activeDocument.activeLayer.textItem.font;

          inputFolder = new Folder('c:/Windows/Fonts');

          folderContent = inputFolder.getFiles(fontName + '*');

         

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

              currentFile = File(folderContent[i]);

              defaultExportFolder = new Folder('d:/someDir');

              destFile = defaultExportFolder + '/' + currentFile.name;

              currentFile.copy(destFile);

          }

      }

       

      I just wondering if there's another better way of finding a relevant font file maybe using more low-level  jsx options.

       

      Thanks!