2016-12-05 160 views
0

我只是試圖讓一個javascript自動爲Photoshop的過程,但我不希望這些零件在我的歷史顯示,一旦我做了。怎麼做?我的意思是並非所有的歷史記錄都應該清除。只有由腳本執行的那些。隱藏部分

謝謝

+0

令人遺憾的是'recentFiles'是最近文件的數組,它是隻讀的。沒有辦法從它的數組中刪除任何文件。你不能使用文件>清除最近打開的文件的圖像處理後(不能照本宣科) –

回答

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; 
} 
+0

找到了解決方案,它的工作原理像魔術,試圖在extendscript和其偉大 –