jsx 从矩形坐标中选择

PSD_MakeSelection_Rectangle
// MAKE RECTANGULAR SELECTION (X,Y)
var topLeft = [0,0];
var topRight = [500,0];
var bottomRight = [500,500];
var bottomLeft = [0,500];
var selectPoints = [topLeft, topRight, bottomRight, bottomLeft];
app.activeDocument.selection.select(selectPoints, SelectionType.REPLACE);

jsx 粘贴到位

PSD_PasteInPlace
// PASTE AT COPIED LOCATION
function pasteInPlace() {
    var desc005 = new ActionDescriptor();
    desc005.putBoolean( stringIDToTypeID( "inPlace" ), true );
    desc005.putEnumerated( charIDToTypeID( "AntA" ), charIDToTypeID( "Annt" ), charIDToTypeID( "Anno" ) );
    executeAction( charIDToTypeID( "past" ), desc005, DialogModes.NO );
}

jsx 创建新文件夹

PSD_CreateFolder
// DOCUMENT DETAILS
var doc = app.activeDocument;
var docName = doc.name;
var docPath = new Folder(doc.path);

// SAVING DETAILS
var saveName = docName.slice(0, -4).concat(".png");
var savePath = new Folder(docPath + "/PNGs");
var saveFinal = savePath + "/" + saveName;

// CREATE SAVE FOLDER IF IT DOESN'T EXIST
if (!savePath.exists) { savePath.create(); }

jsx 从频道中选择

PSD_MakeSelection_Channel
// MAKE SELECTION FORM CHANNEL
function selectChannel(channelName) {
	var desc001 = new ActionDescriptor();
	var ref001 = new ActionReference();
	ref001.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
	desc001.putReference( charIDToTypeID( "null" ), ref001 );
	var ref002 = new ActionReference();
	ref002.putName( charIDToTypeID( "Chnl" ), channelName );
	desc001.putReference( charIDToTypeID( "T   " ), ref002 );
	executeAction( charIDToTypeID( "setd" ), desc001, DialogModes.NO );
}

jsx 从图层蒙版中选择

PSD_MakeSelection_LayerMask
// MAKE SELECTION FROM LAYER MASK
function selectMask() {
    try{
        var desc004 = new ActionDescriptor();
        var ref004 = new ActionReference();
        ref004.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
        desc004.putReference( charIDToTypeID( "null" ), ref004 );
        var ref005 = new ActionReference();
        ref005.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Msk " ) );
        desc004.putReference( charIDToTypeID( "T   " ), ref005 );
        executeAction( charIDToTypeID( "setd" ), desc004, DialogModes.NO );
    } catch(e) {}
}

jsx 裁剪到广场

PSD_CropSquare
// CROP DOCUMENT TO SQUARE SHAPE (BOUNDS PARAMETERS ARE 4-NUMBER ARRAYS: X1, Y1, X2, Y2)
function cropSquare(itemBounds, docBounds) {
    var newBounds = [];
    var docWidth = docBounds[2] - docBounds[0];
    var docHeight = docBounds[3] - docBounds[1];
    var itemWidth = itemBounds[2] - itemBounds[0];
    var itemHeight = itemBounds[3] - itemBounds[1];
    var left = itemBounds[0] - docBounds[0];
    var top = itemBounds[1] - docBounds[1];
    var right = docBounds[2] - itemBounds[2];
    var bottom = docBounds[3] - itemBounds[3];
    if (itemWidth > itemHeight) { var itemSize = itemWidth; } else { var itemSize = itemHeight; }
    var newSize = Math.round(itemSize * 1.02);
    var widthDif = Math.round((newSize - itemWidth) / 2);
    var heightDif = Math.round((newSize - itemHeight) / 2);
    if (widthDif < 0) { var widthDif = widthDif * -1; }
    if (heightDif < 0) { var heightDif = heightDif * -1; }
    if (left == 0) { newBounds.push(docBounds[0]); } else { newBounds.push(itemBounds[0] - widthDif); }
    if (top == 0) { newBounds.push(docBounds[1]); } else { newBounds.push(itemBounds[1] - heightDif); }
    if (right == 0 && left == 0) { newBounds.push(docBounds[2]);
    } else if (right == 0 && left != 0) {
        newBounds.push(docBounds[2]);
        newBounds.splice(0, 1, (docBounds[2] - newSize));
    } else { newBounds.push(newBounds[0] + newSize); }
    if (bottom == 0 && top == 0) { newBounds.push(docBounds[3]);
    } else if (bottom == 0 && top != 0) {
        newBounds.push(docBounds[3]);
        newBounds.splice(1, 1, (docBounds[3] - newSize));
    } else { newBounds.push(newBounds[1] + newSize); }
    doc.crop(newBounds);
}

jsx 隐藏所有但活动层

PSD_HideNonActiveLayers
// MAKE ACTIVE LAYER ONLY VISIBLE LAYER
function onlyVisibleLayer() {
    var desc003 = new ActionDescriptor();
    var list001 = new ActionList();
    var ref003 = new ActionReference();
    ref003.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    list001.putReference( ref003 );
    desc003.putList( charIDToTypeID( "null" ), list001 );
    desc003.putBoolean( charIDToTypeID( "TglO" ), true );
    executeAction( charIDToTypeID( "Shw " ), desc003, DialogModes.NO );
}

jsx 保存TIF

PSD_SaveTIF
// SAVE TIF
function saveTIF(saveFile) {  
    var tifOpts = new TiffSaveOptions;
    tifOpts.alphaChannels = true;
    tifOpts.annotations = true;
    tifOpts.byteOrder = ByteOrder.MACOS;
    tifOpts.embedColorProfile = true;
    tifOpts.imageCompression = TIFFEncoding.NONE; // COMPRESSIONS: NONE, JPEG, TIFFLZW, TIFFZIP
    tifOpts.layers = true;
    tifOpts.spotColors = true;
    tifOpts.transparency = true;
    try {
        app.activeDocument.saveAs(saveFile, tifOpts, false, Extension.LOWERCASE);
    } catch(e) {
        var newSaveFile = new File(saveFile);
        app.activeDocument.saveAs(newSaveFile, tifOpts, false, Extension.LOWERCASE);
    }
}

jsx 保存JPG

PSD_SaveJPG
// SAVE JPG
function saveJPG(saveFile) {  
    var jpgOpts = new JPEGSaveOptions;
    jpgOpts.embedColorProfile = true;
    jpgOpts.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgOpts.matte = MatteType.WHITE;
    jpgOpts.quality = 10; // QUALITY: 0 - 12
    try {
        app.activeDocument.saveAs(saveFile, jpgOpts, true, Extension.LOWERCASE);
    } catch(e) {
        var newSaveFile = new File(saveFile);
        app.activeDocument.saveAs(newSaveFile, jpgOpts, true, Extension.LOWERCASE);
    }
}

jsx 保存PSD

PSD_SavePSD
// SAVE PSD
function savePSD(saveFile) {  
    var psdOpts = new PhotoshopSaveOptions;
    psdOpts.alphaChannels = true;
    psdOpts.annotations = true;
    psdOpts.embedColorProfile = true;
    psdOpts.layers = true;
    psdOpts.spotColors = true;
    try {
        app.activeDocument.saveAs(saveFile, psdOpts, false, Extension.LOWERCASE);
    } catch(e) {
        var newSaveFile = new File(saveFile);
        app.activeDocument.saveAs(newSaveFile, psdOpts, false, Extension.LOWERCASE);
    }
}