Javascript Photoshop ScriptListener访问文件夹中的所有文件
我刚刚用Photoshop cc中的ScriptListener插件制作了一个动作脚本。我不懂javascript。你们能帮我写一些代码,这将帮助我访问源文件夹中的所有文件,然后在应用photoshop过滤器后,用它们的名字将它们保存在文件夹中。 对我的英语很抱歉Javascript Photoshop ScriptListener访问文件夹中的所有文件,javascript,actionscript,photoshop,Javascript,Actionscript,Photoshop,我刚刚用Photoshop cc中的ScriptListener插件制作了一个动作脚本。我不懂javascript。你们能帮我写一些代码,这将帮助我访问源文件夹中的所有文件,然后在应用photoshop过滤器后,用它们的名字将它们保存在文件夹中。 对我的英语很抱歉 // ======================================================= var idOpn = charIDToTypeID( "Opn " ); var desc1 = new Acti
// =======================================================
var idOpn = charIDToTypeID( "Opn " );
var desc1 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc1.putPath( idnull, new File( "C:\\Users\\Данила\\Documents\\PhotoBook\\DSCF1698.JPG" ) );
executeAction( idOpn, desc1, DialogModes.NO );
// =======================================================
var idCnvM = charIDToTypeID( "CnvM" );
var desc2 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
var idGrys = charIDToTypeID( "Grys" );
desc2.putClass( idT, idGrys );
executeAction( idCnvM, desc2, DialogModes.NO );
// =======================================================
var idHghP = charIDToTypeID( "HghP" );
var desc3 = new ActionDescriptor();
var idRds = charIDToTypeID( "Rds " );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idRds, idPxl, 9.200000 );
executeAction( idHghP, desc3, DialogModes.NO );
// =======================================================
var idLvls = charIDToTypeID( "Lvls" );
var desc4 = new ActionDescriptor();
var idpresetKind = stringIDToTypeID( "presetKind" );
var idpresetKindType = stringIDToTypeID( "presetKindType" );
var idpresetKindCustom = stringIDToTypeID( "presetKindCustom" );
desc4.putEnumerated( idpresetKind, idpresetKindType, idpresetKindCustom );
var idAdjs = charIDToTypeID( "Adjs" );
var list1 = new ActionList();
var desc5 = new ActionDescriptor();
var idChnl = charIDToTypeID( "Chnl" );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idChnl, idOrdn, idTrgt );
desc5.putReference( idChnl, ref1 );
var idInpt = charIDToTypeID( "Inpt" );
var list2 = new ActionList();
list2.putInteger( 100 );
list2.putInteger( 125 );
desc5.putList( idInpt, list2 );
var idGmm = charIDToTypeID( "Gmm " );
desc5.putDouble( idGmm, 0.800000 );
var idLvlA = charIDToTypeID( "LvlA" );
list1.putObject( idLvlA, desc5 );
desc4.putList( idAdjs, list1 );
executeAction( idLvls, desc4, DialogModes.NO );
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc6 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idmoveTool = stringIDToTypeID( "moveTool" );
ref2.putClass( idmoveTool );
desc6.putReference( idnull, ref2 );
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc6.putBoolean( iddontRecord, true );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc6.putBoolean( idforceNotify, true );
executeAction( idslct, desc6, DialogModes.NO );
// =======================================================
var idsave = charIDToTypeID( "save" );
var desc7 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc8 = new ActionDescriptor();
var idEQlt = charIDToTypeID( "EQlt" );
desc8.putInteger( idEQlt, 12 );
var idMttC = charIDToTypeID( "MttC" );
var idMttC = charIDToTypeID( "MttC" );
var idNone = charIDToTypeID( "None" );
desc8.putEnumerated( idMttC, idMttC, idNone );
var idJPEG = charIDToTypeID( "JPEG" );
desc7.putObject( idAs, idJPEG, desc8 );
var idIn = charIDToTypeID( "In " );
desc7.putPath( idIn, new File( "C:\\Users\\Данила\\Desktop\\Photobook\\DSCF1698.jpg" ) );
var idDocI = charIDToTypeID( "DocI" );
desc7.putInteger( idDocI, 35 );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveBegin = stringIDToTypeID( "saveBegin" );
desc7.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc7, DialogModes.NO );
// =======================================================
var idsave = charIDToTypeID( "save" );
var desc9 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc10 = new ActionDescriptor();
var idEQlt = charIDToTypeID( "EQlt" );
desc10.putInteger( idEQlt, 12 );
var idMttC = charIDToTypeID( "MttC" );
var idMttC = charIDToTypeID( "MttC" );
var idNone = charIDToTypeID( "None" );
desc10.putEnumerated( idMttC, idMttC, idNone );
var idJPEG = charIDToTypeID( "JPEG" );
desc9.putObject( idAs, idJPEG, desc10 );
var idIn = charIDToTypeID( "In " );
desc9.putPath( idIn, new File( "C:\\Users\\Данила\\Desktop\\Photobook\\DSCF1698.jpg" ) );
var idDocI = charIDToTypeID( "DocI" );
desc9.putInteger( idDocI, 35 );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
desc9.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc9, DialogModes.NO );
// =======================================================
var idCls = charIDToTypeID( "Cls " );
executeAction( idCls, undefined, DialogModes.NO );
给你。我将主进程封装在一个名为doStuff的函数中,然后它保存并关闭文件。注意!它将覆盖现有文件,因此请先备份源文件
//pref pixels
app.preferences.rulerUnits = Units.PIXELS;
var myJpgQuality = 12; // jpeg quality
// get all the files to process
var inFolder = Folder.selectDialog("Please select folder to process");
if (inFolder != null)
{
var fileList = inFolder.getFiles();
}
// look over the first image
var indexFile = fileList[0].toString();
var myDirectoryName = indexFile.substring(0, indexFile.lastIndexOf("/"));
for (var i = 0; i < fileList.length; i++)
{
try
{
var doc = open(fileList[i]);
}
catch(e)
{
alert("Failed to open!");
}
var myFile = fileList[i].toString();
var myFileName = myFile.substring(myFile.lastIndexOf("/") + 1, myFile.lastIndexOf("."));
var myFilePath = myDirectoryName + "/" + myFileName + ".jpg";
// run the main function here
doStuff();
// save
saveAsJpeg(myFilePath);
//close without saving
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
function saveAsJpeg(apath)
{
// jpg file options
var jpgFile = new File(apath);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = myJpgQuality;
activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
function doStuff()
{
// =======================================================
var idCnvM = charIDToTypeID( "CnvM" );
var desc2 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
var idGrys = charIDToTypeID( "Grys" );
desc2.putClass( idT, idGrys );
executeAction( idCnvM, desc2, DialogModes.NO );
// =======================================================
var idHghP = charIDToTypeID( "HghP" );
var desc3 = new ActionDescriptor();
var idRds = charIDToTypeID( "Rds " );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idRds, idPxl, 9.200000 );
executeAction( idHghP, desc3, DialogModes.NO );
// =======================================================
var idLvls = charIDToTypeID( "Lvls" );
var desc4 = new ActionDescriptor();
var idpresetKind = stringIDToTypeID( "presetKind" );
var idpresetKindType = stringIDToTypeID( "presetKindType" );
var idpresetKindCustom = stringIDToTypeID( "presetKindCustom" );
desc4.putEnumerated( idpresetKind, idpresetKindType, idpresetKindCustom );
var idAdjs = charIDToTypeID( "Adjs" );
var list1 = new ActionList();
var desc5 = new ActionDescriptor();
var idChnl = charIDToTypeID( "Chnl" );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idChnl, idOrdn, idTrgt );
desc5.putReference( idChnl, ref1 );
var idInpt = charIDToTypeID( "Inpt" );
var list2 = new ActionList();
list2.putInteger( 100 );
list2.putInteger( 125 );
desc5.putList( idInpt, list2 );
var idGmm = charIDToTypeID( "Gmm " );
desc5.putDouble( idGmm, 0.800000 );
var idLvlA = charIDToTypeID( "LvlA" );
list1.putObject( idLvlA, desc5 );
desc4.putList( idAdjs, list1 );
executeAction( idLvls, desc4, DialogModes.NO );
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc6 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idmoveTool = stringIDToTypeID( "moveTool" );
ref2.putClass( idmoveTool );
desc6.putReference( idnull, ref2 );
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc6.putBoolean( iddontRecord, true );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc6.putBoolean( idforceNotify, true );
executeAction( idslct, desc6, DialogModes.NO );
}
//pref像素
app.preferences.rulerUnits=单位.PIXELS;
var myJpgQuality=12;//jpeg质量
//获取所有要处理的文件
var inFolder=Folder.selectDialog(“请选择要处理的文件夹”);
if(inFolder!=null)
{
var fileList=inFolder.getFiles();
}
//查看第一张图片
var indexFile=fileList[0].toString();
var myDirectoryName=indexFile.substring(0,indexFile.lastIndexOf(“/”);
对于(var i=0;i
谢谢!我也这么做,但没有你这么漂亮。我添加了以下内容:\nvar inputFolder=文件夹(“C:\\Users\\Сааааааа\\Documents\\PhotoBook”)//获取输入文件夹var fileList=inputFolder.getFiles(*.jpg)中的所有文件编码>…然后将主体添加到循环(var i=0;i