Photoshop ScriptListener 访问文件夹中的所有文件
Photoshop ScriptListener to access all files in folder
我刚刚在Photoshop cc中使用ScriptListener插件制作了一个动作脚本。我不懂javascript。你能帮我写一些代码吗,这将有助于我访问源文件夹中的所有文件,然后在应用 photoshop 滤镜后将它们保存在带有其名称的文件夹中。附言对不起我的英语。
// =======================================================
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 );
}
相关文章:
- 如何播放部分音频文件
- 从桌面读取python文件时高亮显示代码
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何使用WCF服务和javascript表单post上传.doc文件
- 当包含另一个asp文件时,是否也包含所有引用的样式和脚本页面
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- Javascript-如何读取json文件中的列并将其保存在Javascript数组中
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- 正在SharePoint 2013母版页中添加JQuery移动文件
- 如何在php文件中获取$.post-ajax传递的值
- 直接下载文件,而不是从window.open(url)
- 如何在android中使用phonegap将文件从一个文件夹移动/复制到另一个文件夹
- 使用压缩的JavaScript文件(不是运行时压缩)
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- 如何在elfinder插件(一个文件管理器插件)上获得上传前事件
- Javascript运行php文件,然后下载文件
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- 我应该如何从xml文件构建一个javascript页面
- 通过Ajax将JavaScript函数传递给PHP文件