#target photoshop
app.bringToFront();
main();
function main(){
if(!documents.length) return;
selectTransparency();
try{
var SB=activeDocument.selection.bounds;
}catch(e){
alert("No selection has been made!");
return;
}
app.activeDocument.selection.makeWorkPath(0.5);
try{
activeDocument.pathItems.getByName('Work Path').name='WP';
}catch(e){
alert("Work Path does not exist!");
return;
}
var currentRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var res = app.activeDocument.resolution;
if( res != 72 ) app.activeDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE);
var pathLayer = activeDocument.activeLayer;
var pathInfo = activeDocument.pathItems.getByName('WP');
var sp = pathInfo.subPathItems.length;
for(var a = 0;a<sp;a++){
var tempPath = app.activeDocument.pathItems.add("Temp Path", extractSubPathInfo('WP',a));
tempPath.makeSelection();
executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO );
tempPath.remove();
activeDocument.activeLayer = pathLayer;
}
if( res != 72 ) app.activeDocument.resizeImage (undefined, undefined, res, ResampleMethod.NONE);
pathInfo.remove();
app.preferences.rulerUnits = currentRulerUnits;
}
function extractSubPathInfo(pathName,subPathNo){
var pathObj = activeDocument.pathItems.getByName(pathName)
var pathArray = new Array();
var pArray = new Array();
for(var i=0;i<pathObj.subPathItems[subPathNo].pathPoints.length;i++){
pArray[i] = new PathPointInfo;
pArray[i].kind = pathObj.subPathItems[subPathNo].pathPoints[i].kind;
pArray[i].anchor = pathObj.subPathItems[subPathNo].pathPoints[i].anchor;
pArray[i].leftDirection = pathObj.subPathItems[subPathNo].pathPoints[i].leftDirection;
pArray[i].rightDirection = pathObj.subPathItems[subPathNo].pathPoints[i].rightDirection;
};
pathArray[pathArray.length] = new Array();
pathArray[pathArray.length - 1] = new SubPathInfo();
pathArray[pathArray.length - 1].operation = pathObj.subPathItems[subPathNo].operation;
pathArray[pathArray.length - 1].closed = pathObj.subPathItems[subPathNo].closed;
pathArray[pathArray.length - 1].entireSubPath = pArray;
return pathArray;
};
function selectTransparency() {
var desc113 = new ActionDescriptor();
var ref83 = new ActionReference();
ref83.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') );
desc113.putReference( charIDToTypeID('null'), ref83 );
var ref84 = new ActionReference();
ref84.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Trsp') );
desc113.putReference( charIDToTypeID('T '), ref84 );
try{
executeAction( charIDToTypeID('setd'), desc113, DialogModes.NO );
}catch(e){}
};