隐藏部分photoshop历史记录

时间:2016-12-05 12:44:40

标签: javascript hide photoshop history

我只是尝试制作一个javascript来自动完成photoshop的流程,但是一旦完成,我就不希望这些部分显示在我的历史记录中。怎么做?我的意思是并不是所有的历史日志都应该被清除。只有脚本执行的那些。

谢谢

1 个答案:

答案 0 :(得分:0)

您无法通过脚本清除最近的文件列表。你也不能通过脚本删除它,因为recentFiles是只读的。

然而,您可以复制最近的文件,并在列表中以相反的顺序重新加载所有处理负载,以便最近的文件列表与您找到的完全一致。

// recentFiles.length = 0; // doesn't work


// get only existing recent files
var myRecentItems = [];
var s= "";
var len = recentFiles.length -1;
var myTempDirectoryName = "c:\\temp";


for (var i = 0; i < recentFiles.length; i++)
{
    var r = recentFiles[i];
    if (r.exists)
    {
        // alert(r + " exists!");
        myRecentItems.push(r);
        s+= r + "\n";
    }
}

alert(myRecentItems.length);

// set to zero
set_recent_file_length(0);

// DO STUFF HERE
// or in this case create small images
// with random names to pad out the recent files list

// create new images
for (var i = 0; i < myRecentItems.length; i++)
{
    var n = get_random_string(8) + ".psd";
    create_new_document(10,10, 72, n);
    // Set savePath and fileName to source path
    var PSDfile = myTempDirectoryName + "\\" + n;
    save_psd(PSDfile);
}

// END DO STUFF


// Load the lrecent files list as we found it
// get the old images back
for (var i = len; i >= 0; i--)
{
    var r = recentFiles[i];
    // open the files in reverse order
    open_image(r);
    //close that document without saving
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

set_recent_file_length(len);


function create_new_document(w, h, imageres, docname)
{
    var docRef = app.documents.add(w, h, imageres, docname);
}

function open_image(f)
{
  try
  {
        var idOpn = charIDToTypeID( "Opn " );
        var desc74 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
        desc74.putPath( idnull, new File( f ) );
        executeAction( idOpn, desc74, DialogModes.NO );
  }
  catch(e)
  {
    alert("Oops!\n" + f + "\n" + e); 
  }
}

function save_psd(f)
{
    // save out the image
    var psdFile = new File(f);
    psdSaveOptions = new PhotoshopSaveOptions();
    psdSaveOptions.embedColorProfile = true;
    psdSaveOptions.alphaChannels = true;  
    activeDocument.saveAs(psdFile, psdSaveOptions, false, Extension.LOWERCASE);
    // close that saved psd
    app.activeDocument.close()
}


function set_recent_file_length(num)
{
    var idsetd = charIDToTypeID( "setd" );
    var desc9 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
    var ref5 = new ActionReference();
    var idPrpr = charIDToTypeID( "Prpr" );
    var idGnrP = charIDToTypeID( "GnrP" );
    ref5.putProperty( idPrpr, idGnrP );
    var idcapp = charIDToTypeID( "capp" );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idTrgt = charIDToTypeID( "Trgt" );
    ref5.putEnumerated( idcapp, idOrdn, idTrgt );
    desc9.putReference( idnull, ref5 );
    var idT = charIDToTypeID( "T   " );
    var desc10 = new ActionDescriptor();
    var idlegacyPathDrag = stringIDToTypeID( "legacyPathDrag" );
    desc10.putBoolean( idlegacyPathDrag, true );
    var idvectorSelectionModifiesLayerSelection = stringIDToTypeID( "vectorSelectionModifiesLayerSelection" );
    desc10.putBoolean( idvectorSelectionModifiesLayerSelection, true );
    var idGnrP = charIDToTypeID( "GnrP" );
    desc9.putObject( idT, idGnrP, desc10 );
    executeAction( idsetd, desc9, DialogModes.NO );
    var idsetd = charIDToTypeID( "setd" );
    var desc11 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
    var ref6 = new ActionReference();
    var idPrpr = charIDToTypeID( "Prpr" );
    var idFlSP = charIDToTypeID( "FlSP" );
    ref6.putProperty( idPrpr, idFlSP );
    var idcapp = charIDToTypeID( "capp" );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idTrgt = charIDToTypeID( "Trgt" );
    ref6.putEnumerated( idcapp, idOrdn, idTrgt );
    desc11.putReference( idnull, ref6 );
    var idT = charIDToTypeID( "T   " );
    var desc12 = new ActionDescriptor();
    var idRcnf = charIDToTypeID( "Rcnf" );
    desc12.putInteger( idRcnf, num );
    var idFlSv = charIDToTypeID( "FlSv" );
    desc11.putObject( idT, idFlSv, desc12 );
    executeAction( idsetd, desc11, DialogModes.NO );
}


function get_random_string(len)
{
    var chars = "abcdefghijklmnopqrstuvwxyz";
    var randString = "";
        for (i=0; i<len; i++)
        {
            var rnd = Math.floor(Math.random()* chars.length);
            randString += chars.substring(rnd, rnd +1)
        }
        return randString;
}