【问题标题】:Photoshop ScriptListener to access all files in folderPhotoshop ScriptListener 访问文件夹中的所有文件
【发布时间】:2014-04-03 06:47:12
【问题描述】:

我刚刚在 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 );

【问题讨论】:

    标签: javascript actionscript photoshop


    【解决方案1】:

    给你。我已经在一个名为 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 );
    }
    

    【讨论】:

    • 谢谢!我也这样做,但没有你那么漂亮。我添加这个:\nvar inputFolder = Folder ("C:\\Users\\Данила\\Documents\\PhotoBook") // get all files in the input folder var fileList = inputFolder.getFiles("*.jpg");
    • ...然后将主体添加到循环中for (var i = 0; i &lt; fileList.length; i++) { open(fileList[i]); var fname = app.activeDocument.name.replace(/\s+/g, '_').replace(/([a-z\d])([A-Z])/g, '$1_$2').toLowerCase();}
    猜你喜欢
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多