Javascript Photoshop JS指定字体

Javascript Photoshop JS指定字体,javascript,photoshop,photoshop-script,Javascript,Photoshop,Photoshop Script,我正试图修改一个脚本来完成我需要它做的事情,并不断得到“TypeError:undefined不是一个对象…我不明白为什么。我复制并粘贴了几乎所有内容。问题是将字体设置为Adobe Garamond ScriptListener有我认为相关的这些行,但我对JS的了解不够,无法理解 var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" ); desc22.putString( idfontPostScri

我正试图修改一个脚本来完成我需要它做的事情,并不断得到“TypeError:undefined不是一个对象…我不明白为什么。我复制并粘贴了几乎所有内容。问题是将字体设置为Adobe Garamond

ScriptListener有我认为相关的这些行,但我对JS的了解不够,无法理解

    var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );
    desc22.putString( idfontPostScriptName, """AGaramondPro-Regular""" );
    var idFntN = charIDToTypeID( "FntN" );
    desc22.putString( idFntN, """Adobe Garamond Pro""" );
    var idFntS = charIDToTypeID( "FntS" );
    desc22.putString( idFntS, """Regular""" );
我的脚本看起来像

    // this script is a variation of the script addTimeStamp.js that is installed with PH7

    //OPENED document has size
    if ( documents.length > 0 )
    {
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.ERROR;
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

try
{
    var docRef = activeDocument;

    // Now create a text layer at the front
    var myLayerRef = docRef.artLayers.add();
    myLayerRef.kind = LayerKind.TEXT;
    myLayerRef.name = "Filename";

    var myTextRef = myLayerRef.textItem;

    // strip the extension off
    var fileNameNoExtension = docRef.name;
    fileNameNoExtension = fileNameNoExtension.split( "." );
    if ( fileNameNoExtension.length > 1 ) {
        fileNameNoExtension.length--;
    }
    fileNameNoExtension = fileNameNoExtension.join(".");

    myTextRef.contents = fileNameNoExtension;



    // off set the text to be in the middle
    myTextRef.position = new Array( docRef.width / 2, docRef.height / 2 );
    myTextRef.size = 135;
     myTextRef.textItem.font = 'AGaramondPro-Regular';
}
catch( e )
{
    // An error occurred. Restore ruler units, then propagate the error back
    // to the user
    preferences.rulerUnits = originalRulerUnits;
    app.displayDialogs = originalDialogMode;
    throw e;
}

// Everything went Ok. Restore ruler units
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
    }
    else
    {
alert( "You must have a document open to add the filename!" );
    }

我的天啊,又回答了我自己的问题。对不起,伙计们

    myTextRef.font = 'AGaramondPro-Regular';

Photoshop倾向于使用Postscript字体名称(如果内存可用的话)-这使问题变得复杂:)