4 Replies Latest reply on Dec 21, 2015 2:45 AM by c.pfaffenbichler

    Need PS script, which will copy properties of selected text

    sb32712384

      Dear Friends,

       

      Looking Photoshop script, which will copy properties of selected text in following format

       

      Roboto,

      Bold,

      14 px,

      #ff0000,

      30 %

       

      Can anyone have idea on this ?

        • 1. Re: Need PS script, which will copy properties of selected text
          c.pfaffenbichler Level 9

          "Selected text" as in

          • a selected Type Layer or

          • selected letters within a Type Layer? (In the latter case I would not be optimistic this can be done.)

           

          "Copy" to the clipboard or write to a txt-file or …?

          • 2. Re: Need PS script, which will copy properties of selected text
            sb32712384 Level 1

            Need to copy properties  of "current type Layer"

            • 3. Re: Need PS script, which will copy properties of selected text
              c.pfaffenbichler Level 9

              "Copy" where? The clipboard or a variable …?

              • 4. Re: Need PS script, which will copy properties of selected text
                c.pfaffenbichler Level 9

                This should get the fonts and sizes of the selected Type Layers.

                To include further features you could try amending the code.

                // thanks to mike hale and paul riggott;

                // 2015, use it at your own risk;

                #target photoshop

                if (app.documents.length > 0) {

                var myDocument = app.activeDocument;

                var theFonts = selectedLayersFonts ();

                alert ("the result:"+"\n"+theFonts.join("\n"))

                };

                ////////////////////////////////////

                function selectedLayersFonts () {

                var theFonts = new Array;

                ////////////////////////////////////

                var selectedLayers = new Array;

                var ref = new ActionReference();

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

                var desc = executeActionGet(ref);

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

                desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

                  var c = desc.count

                  var selectedLayers = new Array();

                  for(var i=0;i<c;i++){

                  try{

                    activeDocument.backgroundLayer;

                    selectedLayers.push(  desc.getReference( i ).getIndex() );

                  }catch(e){

                    selectedLayers.push(  desc.getReference( i ).getIndex()+1 );

                  }

                  }

                }else{

                var ref = new ActionReference();

                ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));

                ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

                try{

                  activeDocument.backgroundLayer;

                  selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);

                }catch(e){

                  selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));

                }

                };

                ////////////////////////////////////

                var theNumber = selectedLayers.length;

                ////////////////////////////////////

                for (var m = theNumber; m >= 0; m--) {

                try {

                var ref = new ActionReference();

                ref.putIndex( charIDToTypeID( "Lyr " ), selectedLayers[m]);

                var layerDesc = executeActionGet(ref);

                var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));

                var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));

                var theName = layerDesc.getString(stringIDToTypeID('name'));

                // if not layer group collect values;

                if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {

                var hasText = layerDesc.hasKey(stringIDToTypeID("textKey"));

                if (hasText == true) {

                var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));

                //checkDesc2 (textDesc)

                var paragraphRangeList = textDesc.getList(stringIDToTypeID('paragraphStyleRange'));

                var kernRange = textDesc.getList(stringIDToTypeID('kerningRange'));

                var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));

                for (var o = 0; o < rangeList.count; o++) {

                var styleDesc = rangeList.getObjectValue(o).getObjectValue(stringIDToTypeID('textStyle'));

                //checkDesc2 (styleDesc)

                var theSize = styleDesc.getUnitDoubleValue(stringIDToTypeID('size'));

                // check for default font;

                if (styleDesc.hasKey(stringIDToTypeID('fontPostScriptName')) == true) {var aFont = styleDesc.getString(stringIDToTypeID('fontPostScriptName'))}

                else {

                  var theDefault = styleDesc.getObjectValue(stringIDToTypeID('baseParentStyle'));

                  var aFont = theDefault.getString(stringIDToTypeID('fontPostScriptName'));

                  };

                theFonts.push([aFont, theSize])

                }

                }

                }

                } catch (e) {};

                }

                return theFonts

                };

                ////////////////////////////////////

                ////////////////////////////////////

                ////////////////////////////////////

                ////// based on code by michael l hale //////

                function checkDesc2 (theDesc) {

                var c = theDesc.count;

                var str = '';

                for(var i=0;i<c;i++){ //enumerate descriptor's keys

                  str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';

                  };

                alert("desc\n\n"+str);

                };

                ////// check //////

                function getValues (theDesc, theNumber) {

                switch (theDesc.getType(theDesc.getKey(theNumber))) {

                case DescValueType.BOOLEANTYPE:

                return theDesc.getBoolean(theDesc.getKey(theNumber));

                break;

                case DescValueType.CLASSTYPE:

                return theDesc.getClass(theDesc.getKey(theNumber));

                break;

                case DescValueType.DOUBLETYPE:

                return theDesc.getDouble(theDesc.getKey(theNumber));

                break;

                case DescValueType.ENUMERATEDTYPE:

                return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStr ingID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));

                break;

                case DescValueType.INTEGERTYPE:

                return theDesc.getInteger(theDesc.getKey(theNumber));

                break;

                case DescValueType.LISTTYPE:

                return theDesc.getList(theDesc.getKey(theNumber));

                break;

                case DescValueType.OBJECTTYPE:

                return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObject Type(theDesc.getKey(theNumber))));

                break;

                case DescValueType.REFERENCETYPE:

                return theDesc.getReference(theDesc.getKey(theNumber));

                break;

                case DescValueType.STRINGTYPE:

                return theDesc.getString(theDesc.getKey(theNumber));

                break;

                case DescValueType.UNITDOUBLE:

                return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUn itDoubleType(theDesc.getKey(theNumber))));

                break;

                default:

                break;

                };

                };