9 Replies Latest reply on Dec 16, 2014 12:12 PM by xbytor2

    Photoshop: Character styles API

    [4RW]

      Hello,

       

      Is there any way how I can access Character styles of a text layer (i.e. bolded out words etc.) via either Extendscript or via com-object - I can't figure it out, can I change only the Layer style itself?

       

      Thank you very much!

        • 1. Re: Photoshop: Character styles API
          c.pfaffenbichler Level 9

          I expect you will have to use Action Manager code, but type Layers have been inconvenient to process via Scripting.

          What exactly are you trying to achieve – could you give an example file and the result you want?

          • 2. Re: Photoshop: Character styles API
            xbytor2 Level 4

            Like c.pfaffenbichler said, it takes some AM code to do this kind of text-related stuff.

            Make a minor change to the text layer then run this script: http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/apps/LastLogEntry.jsx

            To clean the code up, press Fix.

             

            You'll get code that looks something like this:

             

            function ftn1() {
              function cTID(s) { return app.charIDToTypeID(s); };
              function sTID(s) { return app.stringIDToTypeID(s); };
                var desc69 = new ActionDescriptor();
                    var ref9 = new ActionReference();
                    ref9.putEnumerated( cTID('TxLr'), cTID('Ordn'), cTID('Trgt') );
                desc69.putReference( cTID('null'), ref9 );
                    var desc70 = new ActionDescriptor();
                    desc70.putString( cTID('Txt '), "This is a test.  This is another test." );
                        var desc71 = new ActionDescriptor();
                        desc71.putEnumerated( sTID('warpStyle'), sTID('warpStyle'), sTID('warpNone') );
                        desc71.putDouble( sTID('warpValue'), 0.000000 );
                        desc71.putDouble( sTID('warpPerspective'), 0.000000 );
                        desc71.putDouble( sTID('warpPerspectiveOther'), 0.000000 );
                        desc71.putEnumerated( sTID('warpRotate'), cTID('Ornt'), cTID('Hrzn') );
                    desc70.putObject( sTID('warp'), sTID('warp'), desc71 );
                    desc70.putEnumerated( sTID('textGridding'), sTID('textGridding'), cTID('None') );
                    desc70.putEnumerated( cTID('Ornt'), cTID('Ornt'), cTID('Hrzn') );
                    desc70.putEnumerated( cTID('AntA'), cTID('Annt'), cTID('AnCr') );
                        var desc72 = new ActionDescriptor();
                        desc72.putUnitDouble( cTID('Left'), cTID('#Pxl'), -0.071411 );
                        desc72.putUnitDouble( cTID('Top '), cTID('#Pxl'), -60.264404 );
                        desc72.putUnitDouble( cTID('Rght'), cTID('#Pxl'), 999.770142 );
                        desc72.putUnitDouble( cTID('Btom'), cTID('#Pxl'), 18.000000 );
                    desc70.putObject( sTID('bounds'), sTID('bounds'), desc72 );
                        var desc73 = new ActionDescriptor();
                        desc73.putUnitDouble( cTID('Left'), cTID('#Pxl'), 0.301224 );
                        desc73.putUnitDouble( cTID('Top '), cTID('#Pxl'), -50.937546 );
                        desc73.putUnitDouble( cTID('Rght'), cTID('#Pxl'), 997.710938 );
                        desc73.putUnitDouble( cTID('Btom'), cTID('#Pxl'), 1.000015 );
                    desc70.putObject( sTID('boundingBox'), sTID('boundingBox'), desc73 );
                        var list13 = new ActionList();
                            var desc74 = new ActionDescriptor();
                            desc74.putEnumerated( cTID('TEXT'), cTID('TEXT'), cTID('Pnt ') );
                            desc74.putEnumerated( cTID('Ornt'), cTID('Ornt'), cTID('Hrzn') );
                                var desc75 = new ActionDescriptor();
                                desc75.putDouble( sTID('xx'), 1.000000 );
                                desc75.putDouble( sTID('xy'), 0.000000 );
                                desc75.putDouble( sTID('yx'), 0.000000 );
                                desc75.putDouble( sTID('yy'), 1.000000 );
                                desc75.putDouble( sTID('tx'), 0.000000 );
                                desc75.putDouble( sTID('ty'), 0.000000 );
                            desc74.putObject( cTID('Trnf'), cTID('Trnf'), desc75 );
                            desc74.putInteger( sTID('rowCount'), 1 );
                            desc74.putInteger( sTID('columnCount'), 1 );
                            desc74.putBoolean( sTID('rowMajorOrder'), true );
                            desc74.putUnitDouble( sTID('rowGutter'), cTID('#Pxl'), 0.000000 );
                            desc74.putUnitDouble( sTID('columnGutter'), cTID('#Pxl'), 0.000000 );
                            desc74.putUnitDouble( cTID('Spcn'), cTID('#Pxl'), 0.000000 );
                            desc74.putEnumerated( sTID('frameBaselineAlignment'), sTID('frameBaselineAlignment'), sTID('alignByAscent') );
                            desc74.putUnitDouble( sTID('firstBaselineMinimum'), cTID('#Pxl'), 0.000000 );
                                var desc76 = new ActionDescriptor();
                                desc76.putDouble( cTID('Hrzn'), 0.000000 );
                                desc76.putDouble( cTID('Vrtc'), 0.000000 );
                            desc74.putObject( sTID('base'), cTID('Pnt '), desc76 );
                        list13.putObject( sTID('textShape'), desc74 );
                    desc70.putList( sTID('textShape'), list13 );
                        var list14 = new ActionList();
                            var desc77 = new ActionDescriptor();
                            desc77.putInteger( cTID('From'), 0 );
                            desc77.putInteger( cTID('T  '), 15 );
                                var desc78 = new ActionDescriptor();
                                desc78.putBoolean( sTID('styleSheetHasParent'), true );
                                desc78.putUnitDouble( cTID('Sz  '), cTID('#Pxl'), 72.000000 );
                                desc78.putUnitDouble( sTID('impliedFontSize'), cTID('#Pxl'), 72.000000 );
                                desc78.putEnumerated( sTID('digitSet'), sTID('digitSet'), sTID('defaultDigits') );
                                desc78.putUnitDouble( sTID('markYDistFromBaseline'), cTID('#Pxl'), 100.000000 );
                                    var desc79 = new ActionDescriptor();
                                    desc79.putDouble( cTID('Rd  '), 255.000000 );
                                    desc79.putDouble( cTID('Grn '), 0.000000 );
                                    desc79.putDouble( cTID('Bl  '), 0.000000 );
                                desc78.putObject( cTID('Clr '), cTID('RGBC'), desc79 );
                                    var desc80 = new ActionDescriptor();
                                    desc80.putString( sTID('fontPostScriptName'), "MyriadPro-Regular" );
                                    desc80.putString( cTID('FntN'), "Myriad Pro" );
                                    desc80.putString( cTID('FntS'), "Regular" );
                                    desc80.putInteger( cTID('Scrp'), 0 );
                                    desc80.putInteger( cTID('FntT'), 0 );
                                    desc80.putUnitDouble( cTID('Sz  '), cTID('#Pxl'), 12.000000 );
                                    desc80.putUnitDouble( sTID('impliedFontSize'), cTID('#Pxl'), 12.000000 );
                                    desc80.putDouble( cTID('HrzS'), 100.000000 );
                                    desc80.putDouble( cTID('VrtS'), 100.000000 );
                                    desc80.putBoolean( sTID('syntheticBold'), false );
                                    desc80.putBoolean( sTID('syntheticItalic'), false );
                                    desc80.putBoolean( sTID('autoLeading'), true );
                                    desc80.putInteger( cTID('Trck'), 0 );
                                    desc80.putUnitDouble( cTID('Bsln'), cTID('#Pxl'), 0.000000 );
                                    desc80.putUnitDouble( sTID('impliedBaselineShift'), cTID('#Pxl'), 0.000000 );
                                    desc80.putDouble( sTID('characterRotation'), 0.000000 );
                                    desc80.putEnumerated( cTID('AtKr'), cTID('AtKr'), sTID('metricsKern') );
                                    desc80.putEnumerated( sTID('fontCaps'), sTID('fontCaps'), cTID('Nrml') );
                                    desc80.putEnumerated( sTID('digitSet'), sTID('digitSet'), sTID('defaultDigits') );
                                    desc80.putEnumerated( sTID('dirOverride'), sTID('dirOverride'), sTID('dirOverrideDefault') );
                                    desc80.putEnumerated( sTID('kashidas'), sTID('kashidas'), sTID('kashidaDefault') );
                                    desc80.putEnumerated( sTID('diacVPos'), sTID('diacVPos'), sTID('diacVPosOpenType') );
                                    desc80.putUnitDouble( sTID('diacXOffset'), cTID('#Pxl'), 0.000000 );
                                    desc80.putUnitDouble( sTID('diacYOffset'), cTID('#Pxl'), 0.000000 );
                                    desc80.putUnitDouble( sTID('markYDistFromBaseline'), cTID('#Pxl'), 100.000000 );
                                    desc80.putEnumerated( sTID('baseline'), sTID('baseline'), cTID('Nrml') );
                                    desc80.putEnumerated( sTID('otbaseline'), sTID('otbaseline'), cTID('Nrml') );
                                    desc80.putEnumerated( sTID('strikethrough'), sTID('strikethrough'), sTID('strikethroughOff') );
                                    desc80.putEnumerated( cTID('Undl'), cTID('Undl'), sTID('underlineOff') );
                                    desc80.putUnitDouble( sTID('underlineOffset'), cTID('#Pxl'), 0.000000 );
                                    desc80.putBoolean( sTID('ligature'), true );
                                    desc80.putBoolean( sTID('altligature'), false );
                                    desc80.putBoolean( sTID('contextualLigatures'), false );
                                    desc80.putBoolean( sTID('alternateLigatures'), false );
                                    desc80.putBoolean( sTID('oldStyle'), false );
                                    desc80.putBoolean( sTID('fractions'), false );
                                    desc80.putBoolean( sTID('ordinals'), false );
                                    desc80.putBoolean( sTID('swash'), false );
                                    desc80.putBoolean( sTID('titling'), false );
                                    desc80.putBoolean( sTID('connectionForms'), false );
                                    desc80.putBoolean( sTID('stylisticAlternates'), false );
                                    desc80.putBoolean( sTID('ornaments'), false );
                                    desc80.putBoolean( sTID('justificationAlternates'), false );
                                    desc80.putEnumerated( sTID('figureStyle'), sTID('figureStyle'), cTID('Nrml') );
                                    desc80.putBoolean( sTID('proportionalMetrics'), false );
                                    desc80.putBoolean( sTID('kana'), false );
                                    desc80.putBoolean( sTID('italics'), false );
                                    desc80.putBoolean( sTID('ruby'), false );
                                    desc80.putEnumerated( sTID('baselineDirection'), sTID('baselineDirection'), sTID('rotated') );
                                    desc80.putEnumerated( sTID('textLanguage'), sTID('textLanguage'), sTID('englishLanguage') );
                                    desc80.putEnumerated( sTID('japaneseAlternate'), sTID('japaneseAlternate'), sTID('defaultForm') );
                                    desc80.putDouble( sTID('mojiZume'), 0.000000 );
                                    desc80.putEnumerated( sTID('gridAlignment'), sTID('gridAlignment'), sTID('roman') );
                                    desc80.putBoolean( sTID('enableWariChu'), false );
                                    desc80.putInteger( sTID('wariChuCount'), 2 );
                                    desc80.putInteger( sTID('wariChuLineGap'), 0 );
                                    desc80.putDouble( sTID('wariChuScale'), 0.500000 );
                                    desc80.putInteger( sTID('wariChuWidow'), 2 );
                                    desc80.putInteger( sTID('wariChuOrphan'), 2 );
                                    desc80.putEnumerated( sTID('wariChuJustification'), sTID('wariChuJustification'), sTID('wariChuAutoJustify') );
                                    desc80.putInteger( sTID('tcyUpDown'), 0 );
                                    desc80.putInteger( sTID('tcyLeftRight'), 0 );
                                    desc80.putDouble( sTID('leftAki'), -1.000000 );
                                    desc80.putDouble( sTID('rightAki'), -1.000000 );
                                    desc80.putInteger( sTID('jiDori'), 0 );
                                    desc80.putBoolean( sTID('noBreak'), false );
                                        var desc81 = new ActionDescriptor();
                                        desc81.putDouble( cTID('Rd  '), 0.000000 );
                                        desc81.putDouble( cTID('Grn '), 0.000000 );
                                        desc81.putDouble( cTID('Bl  '), 0.000000 );
                                    desc80.putObject( cTID('Clr '), cTID('RGBC'), desc81 );
                                        var desc82 = new ActionDescriptor();
                                        desc82.putDouble( cTID('Rd  '), 0.000000 );
                                        desc82.putDouble( cTID('Grn '), 0.000000 );
                                        desc82.putDouble( cTID('Bl  '), 0.000000 );
                                    desc80.putObject( sTID('strokeColor'), cTID('RGBC'), desc82 );
                                    desc80.putBoolean( cTID('Fl  '), true );
                                    desc80.putBoolean( cTID('Strk'), false );
                                    desc80.putBoolean( sTID('fillFirst'), true );
                                    desc80.putBoolean( sTID('fillOverPrint'), false );
                                    desc80.putBoolean( sTID('strokeOverPrint'), false );
                                    desc80.putEnumerated( sTID('lineCap'), sTID('lineCap'), sTID('buttCap') );
                                    desc80.putEnumerated( sTID('lineJoin'), sTID('lineJoin'), sTID('miterJoin') );
                                    desc80.putUnitDouble( sTID('lineWidth'), cTID('#Pxl'), 1.000000 );
                                    desc80.putUnitDouble( sTID('miterLimit'), cTID('#Pxl'), 4.000000 );
                                    desc80.putDouble( sTID('lineDashoffset'), 0.000000 );
                                desc78.putObject( sTID('baseParentStyle'), cTID('TxtS'), desc80 );
                            desc77.putObject( cTID('TxtS'), cTID('TxtS'), desc78 );
                        list14.putObject( cTID('Txtt'), desc77 );
                            var desc83 = new ActionDescriptor();
                            desc83.putInteger( cTID('From'), 15 );
                            desc83.putInteger( cTID('T  '), 17 );
                                var desc84 = new ActionDescriptor();
                                desc84.putBoolean( sTID('styleSheetHasParent'), true );
                                desc84.putUnitDouble( cTID('Sz  '), cTID('#Pxl'), 72.000000 );
                                desc84.putUnitDouble( sTID('impliedFontSize'), cTID('#Pxl'), 72.000000 );
                                desc84.putEnumerated( sTID('digitSet'), sTID('digitSet'), sTID('defaultDigits') );
                                desc84.putUnitDouble( sTID('markYDistFromBaseline'), cTID('#Pxl'), 100.000000 );
                            desc83.putObject( cTID('TxtS'), cTID('TxtS'), desc84 );
                        list14.putObject( cTID('Txtt'), desc83 );
                            var desc85 = new ActionDescriptor();
                            desc85.putInteger( cTID('From'), 17 );
                            desc85.putInteger( cTID('T  '), 37 );
                                var desc86 = new ActionDescriptor();
                                desc86.putBoolean( sTID('styleSheetHasParent'), true );
                                desc86.putString( sTID('fontPostScriptName'), "MyriadPro-BoldIt" );
                                desc86.putString( cTID('FntN'), "Myriad Pro" );
                                desc86.putString( cTID('FntS'), "Bold Italic" );
                                desc86.putInteger( cTID('Scrp'), 0 );
                                desc86.putInteger( cTID('FntT'), 0 );
                                desc86.putUnitDouble( cTID('Sz  '), cTID('#Pxl'), 72.000000 );
                                desc86.putUnitDouble( sTID('impliedFontSize'), cTID('#Pxl'), 72.000000 );
                                desc86.putEnumerated( sTID('digitSet'), sTID('digitSet'), sTID('defaultDigits') );
                                desc86.putUnitDouble( sTID('markYDistFromBaseline'), cTID('#Pxl'), 100.000000 );
                            desc85.putObject( cTID('TxtS'), cTID('TxtS'), desc86 );
                        list14.putObject( cTID('Txtt'), desc85 );
                            var desc87 = new ActionDescriptor();
                            desc87.putInteger( cTID('From'), 37 );
                            desc87.putInteger( cTID('T  '), 39 );
                                var desc88 = new ActionDescriptor();
                                desc88.putBoolean( sTID('styleSheetHasParent'), true );
                                desc88.putUnitDouble( cTID('Sz  '), cTID('#Pxl'), 72.000000 );
                                desc88.putUnitDouble( sTID('impliedFontSize'), cTID('#Pxl'), 72.000000 );
                                desc88.putEnumerated( sTID('digitSet'), sTID('digitSet'), sTID('defaultDigits') );
                                desc88.putUnitDouble( sTID('markYDistFromBaseline'), cTID('#Pxl'), 100.000000 );
                            desc87.putObject( cTID('TxtS'), cTID('TxtS'), desc88 );
                        list14.putObject( cTID('Txtt'), desc87 );
                    desc70.putList( cTID('Txtt'), list14 );
                        var list15 = new ActionList();
                            var desc89 = new ActionDescriptor();
                            desc89.putInteger( cTID('From'), 0 );
                            desc89.putInteger( cTID('T  '), 39 );
                                var desc90 = new ActionDescriptor();
                                desc90.putBoolean( sTID('styleSheetHasParent'), true );
                                desc90.putEnumerated( cTID('Algn'), cTID('Alg '), cTID('Left') );
                                desc90.putUnitDouble( sTID('firstLineIndent'), cTID('#Pxl'), 0.000000 );
                                desc90.putUnitDouble( sTID('impliedFirstLineIndent'), cTID('#Pxl'), 0.000000 );
                                desc90.putUnitDouble( sTID('startIndent'), cTID('#Pxl'), 0.000000 );
                                desc90.putUnitDouble( sTID('impliedStartIndent'), cTID('#Pxl'), 0.000000 );
                                desc90.putUnitDouble( sTID('endIndent'), cTID('#Pxl'), 0.000000 );
                                desc90.putUnitDouble( sTID('impliedEndIndent'), cTID('#Pxl'), 0.000000 );
                                desc90.putUnitDouble( sTID('spaceBefore'), cTID('#Pxl'), 0.000000 );
                                desc90.putUnitDouble( sTID('impliedSpaceBefore'), cTID('#Pxl'), 0.000000 );
                                desc90.putUnitDouble( sTID('spaceAfter'), cTID('#Pxl'), 0.000000 );
                                desc90.putUnitDouble( sTID('impliedSpaceAfter'), cTID('#Pxl'), 0.000000 );
                                desc90.putInteger( sTID('dropCapMultiplier'), 1 );
                                desc90.putDouble( sTID('autoLeadingPercentage'), 1.200000 );
                                desc90.putEnumerated( sTID('leadingType'), sTID('leadingType'), sTID('leadingBelow') );
                                desc90.putEnumerated( sTID('directionType'), sTID('directionType'), sTID('dirLeftToRight') );
                                desc90.putEnumerated( sTID('kashidaWidthType'), sTID('kashidaWidthType'), sTID('kashidaWidthMedium') );
                                desc90.putEnumerated( sTID('justificationMethodType'), sTID('justificationMethodType'), sTID('justifMethodAutomatic') );
                                desc90.putBoolean( sTID('hyphenate'), true );
                                desc90.putInteger( sTID('hyphenateWordSize'), 6 );
                                desc90.putInteger( sTID('hyphenatePreLength'), 2 );
                                desc90.putInteger( sTID('hyphenatePostLength'), 2 );
                                desc90.putInteger( sTID('hyphenateLimit'), 0 );
                                desc90.putDouble( sTID('hyphenationZone'), 36.000000 );
                                desc90.putBoolean( sTID('hyphenateCapitalized'), true );
                                desc90.putDouble( sTID('hyphenationPreference'), 0.500000 );
                                desc90.putDouble( sTID('justificationWordMinimum'), 0.800000 );
                                desc90.putDouble( sTID('justificationWordDesired'), 1.000000 );
                                desc90.putDouble( sTID('justificationWordMaximum'), 1.330000 );
                                desc90.putDouble( sTID('justificationLetterMinimum'), 0.000000 );
                                desc90.putDouble( sTID('justificationLetterDesired'), 0.000000 );
                                desc90.putDouble( sTID('justificationLetterMaximum'), 0.000000 );
                                desc90.putDouble( sTID('justificationGlyphMinimum'), 1.000000 );
                                desc90.putDouble( sTID('justificationGlyphDesired'), 1.000000 );
                                desc90.putDouble( sTID('justificationGlyphMaximum'), 1.000000 );
                                desc90.putEnumerated( sTID('singleWordJustification'), cTID('Alg '), cTID('JstA') );
                                desc90.putBoolean( sTID('hangingRoman'), false );
                                desc90.putInteger( sTID('autoTCY'), 0 );
                                desc90.putBoolean( sTID('keepTogether'), true );
                                desc90.putEnumerated( sTID('burasagari'), sTID('burasagari'), sTID('burasagariNone') );
                                desc90.putEnumerated( sTID('preferredKinsokuOrder'), sTID('preferredKinsokuOrder'), sTID('pushIn') );
                                desc90.putBoolean( sTID('kurikaeshiMojiShori'), false );
                                desc90.putBoolean( sTID('textEveryLineComposer'), false );
                                desc90.putDouble( sTID('defaultTabWidth'), 36.000000 );
                                    var desc91 = new ActionDescriptor();
                                    desc91.putString( sTID('fontPostScriptName'), "MyriadPro-Regular" );
                                    desc91.putString( cTID('FntN'), "Myriad Pro" );
                                    desc91.putString( cTID('FntS'), "Regular" );
                                    desc91.putInteger( cTID('Scrp'), 0 );
                                    desc91.putInteger( cTID('FntT'), 0 );
                                    desc91.putUnitDouble( cTID('Sz  '), cTID('#Pxl'), 12.000000 );
                                    desc91.putDouble( cTID('HrzS'), 100.000000 );
                                    desc91.putDouble( cTID('VrtS'), 100.000000 );
                                    desc91.putBoolean( sTID('syntheticBold'), false );
                                    desc91.putBoolean( sTID('syntheticItalic'), false );
                                    desc91.putBoolean( sTID('autoLeading'), true );
                                    desc91.putInteger( cTID('Trck'), 0 );
                                    desc91.putUnitDouble( cTID('Bsln'), cTID('#Pxl'), 0.000000 );
                                    desc91.putDouble( sTID('characterRotation'), 0.000000 );
                                    desc91.putEnumerated( cTID('AtKr'), cTID('AtKr'), sTID('metricsKern') );
                                    desc91.putEnumerated( sTID('fontCaps'), sTID('fontCaps'), cTID('Nrml') );
                                    desc91.putEnumerated( sTID('digitSet'), sTID('digitSet'), sTID('arabicDigits') );
                                    desc91.putEnumerated( sTID('kashidas'), sTID('kashidas'), sTID('kashidaDefault') );
                                    desc91.putEnumerated( sTID('diacVPos'), sTID('diacVPos'), sTID('diacVPosOpenType') );
                                    desc91.putUnitDouble( sTID('diacXOffset'), cTID('#Pxl'), 0.000000 );
                                    desc91.putUnitDouble( sTID('diacYOffset'), cTID('#Pxl'), 0.000000 );
                                    desc91.putUnitDouble( sTID('markYDistFromBaseline'), cTID('#Pxl'), 0.000000 );
                                    desc91.putEnumerated( sTID('baseline'), sTID('baseline'), cTID('Nrml') );
                                    desc91.putEnumerated( sTID('strikethrough'), sTID('strikethrough'), sTID('strikethroughOff') );
                                    desc91.putEnumerated( cTID('Undl'), cTID('Undl'), sTID('underlineOff') );
                                    desc91.putBoolean( sTID('ligature'), true );
                                    desc91.putBoolean( sTID('altligature'), false );
                                    desc91.putBoolean( sTID('contextualLigatures'), true );
                                    desc91.putBoolean( sTID('alternateLigatures'), false );
                                    desc91.putBoolean( sTID('oldStyle'), false );
                                    desc91.putBoolean( sTID('fractions'), false );
                                    desc91.putBoolean( sTID('ordinals'), false );
                                    desc91.putBoolean( sTID('swash'), false );
                                    desc91.putBoolean( sTID('titling'), false );
                                    desc91.putBoolean( sTID('connectionForms'), false );
                                    desc91.putBoolean( sTID('stylisticAlternates'), false );
                                    desc91.putBoolean( sTID('ornaments'), false );
                                    desc91.putEnumerated( sTID('figureStyle'), sTID('figureStyle'), cTID('Nrml') );
                                    desc91.putEnumerated( sTID('baselineDirection'), sTID('baselineDirection'), sTID('withStream') );
                                    desc91.putEnumerated( sTID('textLanguage'), sTID('textLanguage'), sTID('englishLanguage') );
                                        var desc92 = new ActionDescriptor();
                                        desc92.putDouble( cTID('Rd  '), 0.000000 );
                                        desc92.putDouble( cTID('Grn '), 0.000000 );
                                        desc92.putDouble( cTID('Bl  '), 0.000000 );
                                    desc91.putObject( cTID('Clr '), cTID('RGBC'), desc92 );
                                        var desc93 = new ActionDescriptor();
                                        desc93.putDouble( cTID('Rd  '), 0.000000 );
                                        desc93.putDouble( cTID('Grn '), 0.000000 );
                                        desc93.putDouble( cTID('Bl  '), 0.000000 );
                                    desc91.putObject( sTID('strokeColor'), cTID('RGBC'), desc93 );
                                desc90.putObject( sTID('defaultStyle'), cTID('TxtS'), desc91 );
                            desc89.putObject( sTID('paragraphStyle'), sTID('paragraphStyle'), desc90 );
                        list15.putObject( sTID('paragraphStyleRange'), desc89 );
                    desc70.putList( sTID('paragraphStyleRange'), list15 );
                        var list16 = new ActionList();
                    desc70.putList( sTID('kerningRange'), list16 );
                desc69.putObject( cTID('T  '), cTID('TxLr'), desc70 );
                executeAction( cTID('setd'), desc69, DialogModes.NO );
            };
            

             

            This code describes how a Text Layer ActionDescriptor is laid out. It has one section of text that is red and another section that is bold-italic so there are two style ranges.

            The code to get the Text Layer descriptor is this simple:

             

            function getLayerDescriptor() {
              var ref = new ActionReference();
              ref.putEnumerated(cTID("Lyr "), cTID("Ordn"), cTID("Trgt"));
              return executeActionGet(ref)
            };
            

             

            This bit of code assumes that the document and layer are active/selected. But once you have it, the previous block of code shows you how to go in and get the info that you need.

             

            There is also these bits of code that mucks around with Text/Style Ranges:

            http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xlib/Text.jsx

            http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/xlib/TextTest.jsx

             

            In other words, futzing around with text styles is not a pretty thing in PS/JS. InDesign has far better Text APIs.

            • 3. Re: Photoshop: Character styles API
              [4RW] Level 1

              What I want to achieve is something like this:
              extract the text including the formatting in XML (or json object that I convert to xml including some formatting tags) -> translate the text -> import the translations including the formatting.

              (I know different languages has different lengths, some are RTL and so on - there will be post-processing needed -> this will save a lot of time though).

               

              Thank you so much for pointing out Actions Manager - didn't know that something like that even exists!

              • 4. Re: Photoshop: Character styles API
                [4RW] Level 1

                xbytor2:
                Thank you so much for this huge reply - it will take me a while to bite through the code - is this computer generated or written by hand O_o

                Also great snippets of code - I will hopefully make it work somehow

                • 5. Re: Photoshop: Character styles API
                  JJMack Most Valuable Participant

                  The term AM code means Action Manager Code.   When you record actions they are recorded and played back through Adobe Photoshop's Action Manager.  Not all things Photoshop things can be recorded. Scripting also has many limitations.  Many Photoshop features can not be programmed using Photoshop Scripting feature and Adobe Document Object Mode. DOM...   To get around this Adobe has a Plugin named Scriptlistener.   The Scriptlisiner  Plugin is more or less like a Script recorder like the Action Palette's record button.  However it has no UI.  Once installed it will record write two log files onto your desktop.  One log is written in VBS scripting syntax and the other in Javascript syntax,  Anything that you do in Photoshop  that can be recorded into an action step will be written to these logs. Like Actions the code is step step step hard coded no logic.  However it is in a scripting language syntax code for the Action Manager  and the code can easily be edit.  Hard coded values can be replaced with variables and logic can be added.  So function for use in scripts can be coded and most of the limitations of Adobe DOM can be programmed around using Action Manager code  The code you see X posting above was posted was generated by using Photoshop with the Scriptlistener plug-in installed and cleaned up some be X.  As you se text is very complex..  While there is no UI or controls available for the Scriptlistener you can more or less control its recording  by altering the log files attribute.  I have changed the VBS log file attribute to Read only which disables the VBS recording.   I use windows and created a Bat file that lets be control the Javascript log. With the bat file running I can turn on and off the recording clear and edit the log so I can extract the function I need.  I use a shortcut to start the bat in a small dos window on my desktop bottom right corner. The bat file looks like this:

                  @Echo Off

                  :loop

                  CLS

                  rem Display Log File Size

                  Dir "%USERPROFILE%\Desktop\ScriptingListenerJS.log" /T:W /4 | find "%ScriptingListenerJS.log"

                  rem Display Log Attributes  R read only Locked no R log is Unlocked

                  Attrib "%USERPROFILE%\Desktop\ScriptingListenerJS.log"

                  Rem If timeout is use the above display lines will refresh over time else you need to use enter or number

                  CHOICE /C 123456 /N /T 300 /D 6 /M "Enter:1 to Lock, 2 to Unlock, 3 to Edit, 4 to Clear, 5 To Exit :"
                  Echo %ERRORLEVEL%
                  if %ERRORLEVEL%==6 goto timeout
                  if %ERRORLEVEL%==1 goto one
                  if %ERRORLEVEL%==2 goto two
                  if %ERRORLEVEL%==3 goto three
                  if %ERRORLEVEL%==4 goto four
                  if %ERRORLEVEL%==5 goto five
                  goto loop

                  :timeout

                  goto loop

                  :one

                  Attrib +R "%USERPROFILE%\Desktop\ScriptingListenerJS.log"
                  goto loop

                  :two

                  Attrib -R "%USERPROFILE%\Desktop\ScriptingListenerJS.log"
                  goto loop

                  :three

                          Rem inline command use CMD independate command use start

                  CMD /C notepad "%USERPROFILE%\Desktop\ScriptingListenerJS.log"
                  remStart notepad "%USERPROFILE%\Desktop\ScriptingListenerJS.log"
                  goto loop

                  :four

                  Rem If the script log file is unlocked not read only  this echo will clear it

                  Echo. > "%USERPROFILE%\Desktop\ScriptingListenerJS.log"
                  goto loop

                  :five

                  EXIT
                  • 6. Re: Photoshop: Character styles API
                    Pedro Cortez Marques Level 3

                    There is a very good alternative here.

                    Just intall the "JSON Action Manager" folder on you Mac or PC root user folder (or change it to whether you need and start using the text operator

                     

                    http://www.tonton-pixel.com/blog/

                     

                    http://www.tonton-pixel.com/blog/json-photoshop-scripting/json-action-manager/

                     

                    Here are all the jamText functions

                    http://www.tonton-pixel.com/JSON%20Action%20Manager/jsDoc/symbols/jamText.html

                     

                    I have used it for other reasons (like to get custom paths and patterns without even having to load them onto photoshop).

                    • 7. Re: Photoshop: Character styles API
                      [4RW] Level 1

                      Hi Pedro,

                      Yes, this library is exactly what I've been looking for - it is awesome 

                      Thanks!

                      • 8. Re: Photoshop: Character styles API
                        [4RW] Level 1

                        Thank you for the description, now I do understand the background It is interesting how Adobe solved the incomplete API.

                        • 9. Re: Photoshop: Character styles API
                          xbytor2 Level 4

                          If you'd rather use XML, there are some scripts in xtools that you can use.

                          First, record an action with one step where you do non-edit. I just delete a letter then type it back in.

                          This makes PS think the text layer was modified so it generates an action step that recreates the text layer.

                          Next, run http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/apps/ActionToXML.jsx on this action.

                          This creates an XML file representation of the action.

                          Translate and make what ever changes you need to the xml file.

                          Now, convert the XML file to an action file with http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/apps/ActionFileFromXML.jsx .

                          Finally, either load the action and run it to construct your new translated text layer, or convert

                          the action file to a JavaScript file with http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/apps/ActionFileToJavascript .jsx

                          which will also recreate your text layer.