0 Replies Latest reply on Apr 28, 2009 2:10 PM by Steven..

    Script for font managment

    Steven.. Level 3

      I often get a file created with the Indesign Package function. The fonts are in the Fonts folder and I have to create a shortcut in the Indesign Fonts Folder, for the Fonts not to be missing. So I created a Script that adds this shortcut

      var fontFolder = Folder(File(BridgeTalk.getAppPath("indesign-"+app.version)).parent+'/Fonts/');

      if(app.documents.length){

           var doc = app.activeDocument;

           var docFontsFolder = File(doc.filePath+'/Fonts/');

           if(docFontsFolder.exists==true){

                var rapidDlg = new Window('dialog',"Select name for shortcut",undefined);

                buildWindow();

                var result = '';

                rapidDlg.show();

                if(result.length){

                     var newShortcut= File(fontFolder+'/'+result);

                     if (newShortcut.exists==false){

                          if(newShortcut.createAlias(docFontsFolder.fsName)) {

                               app.updateFonts();

                               alert('Shortcut has been created');

                          }

                     else{

                          alert('Creating shortcut has failed');

                     }

                     }

                     else{

                          alert('Shortcut by this name already exists, please try again with new name');

                     }

                }

           }

                else alert('No Font Folder can be found');

           }

      else{

      alert('No Documents are open')     

      }

       

      function buildWindow(){

      // Properties for rapidDlg.EditText1

           rapidDlg.EditText1 = rapidDlg.add('edittext',undefined,undefined);

           rapidDlg.EditText1.characters = 50;

       

      // Properties for rapidDlg.Group1

           rapidDlg.Group1 = rapidDlg.add('group',undefined);

           rapidDlg.Group1.alignment = ['right',' '];

       

      // Properties for rapidDlg.Group1.Button1

           rapidDlg.Group1.Button1 = rapidDlg.Group1.add('button',undefined,"OK", {name:"ok"});

           rapidDlg.Group1.Button1.onClick = function(){

                result=rapidDlg.EditText1.text;

                rapidDlg.close()

           }

       

      // Properties for rapidDlg.Group1.Button2

           rapidDlg.Group1.Button2 = rapidDlg.Group1.add('button',undefined,"Cancel", {name:"cancel"});

      }

       

       

      and another script to remove your shortcuts

      var  fontFolder= Folder(File(BridgeTalk.getAppPath("indesign-"+app.version)).parent+'/Fonts/');

      var allFiles=fontFolder.getFiles('*');

      var arrayOfAlias=new Array();

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

           if(allFiles[i].alias){

                arrayOfAlias[arrayOfAlias.length]=(allFiles[i].displayName);

           }

      }

      if (arrayOfAlias.length){

           var rapidDlg = new Window('dialog',"Remove Shortcuts",undefined);

           buildWindow();

           rapidDlg.show();

      }

      else{

                alert('No Shortcuts Found');

      }

       

      function buildWindow(){

           rapidDlg.orientation = "row";

       

      // Properties for rapidDlg.Group1

           rapidDlg.Group1 = rapidDlg.add('group',undefined);

           rapidDlg.Group1.orientation = "column";

       

      // Properties for rapidDlg.Group1.ListBox1

           rapidDlg.Group1.ListBox1 = rapidDlg.Group1.add('listbox',undefined,undefined, {items:arrayOfAlias});

           rapidDlg.Group1.ListBox1.selection = 0;

       

      // Properties for rapidDlg.Group1.Button2

           rapidDlg.Group1.Button2 = rapidDlg.Group1.add('button',undefined,"Remove");

           rapidDlg.Group1.Button2.onClick = function(){

                File(fontFolder+'/'+rapidDlg.Group1.ListBox1.selection.text).remove();

                rapidDlg.Group1.ListBox1.remove(rapidDlg.Group1.ListBox1.selection);

           }

       

      // Properties for rapidDlg.Group2

           rapidDlg.Group2 = rapidDlg.add('group',undefined);

           rapidDlg.Group2.alignment = [' ','top'];

           rapidDlg.Group2.orientation = "column";

       

      // Properties for rapidDlg.Group2.Button1

           rapidDlg.Group2.Button1 = rapidDlg.Group2.add('button',undefined,"OK", {name:"ok"});

       

      }

       

      Steven

      http://scriptui.com