2014-10-03 107 views
0

我需要將幾張圖像分組到一個photoshop文件中,並嘗試尋找更優化的路徑。我知道我可以使用applescript來做這樣的事情。將圖像放入當前打開的Photoshop文檔(applescript)

tell application id "com.adobe.Photoshop" 
    activate 
    open file (CurrentImg) 
    duplicate layer 1 of current document to end of NewDocRef 
end tell 
-- CurrentImg is some file path and NewDocRef is a path to some other open document 

我可以使用open打開每個圖像,並將其移動到一個文檔中。我的問題是,有沒有人有更好的方式將圖像直接放入打開的文檔中。尋找只是拖動一個圖像的效果。我打開有一個JavaScript函數來做到這一點。 (我不知道JavaScript,但我可以設法大部分了解我讀的內容。)

回答

2

我在ExtendScript中寫道它。 測試OSX上的Photoshop 2014 CC

// based on this stackoverflow 
// http://stackoverflow.com/a/2780624/1770432 

var main = function(arguments, body) { 
    if (app.documents.length < 1) { 
    // abort no file to place imports in 
    return; 
    } 
    // filter does not work on OSX 
    var files = File.openDialog("Select your files to place", "*.*", true); 
    if (files.length < 1 || files === null) { 
    // abort 
    // nothing selected or canceld 
    return; 
    } else { 
    // got something 
    var doc = app.activeDocument; 
    // loop all files 
    for (var i = 0; i < files.length; i++) { 
     // we use a try catch to sort out files Photoshop cant handle 
     try { 
     var curr_file = app.open(files[i]); // one of them 
     curr_file.selection.selectAll(); 
     curr_file.selection.copy(); 
     curr_file.close(SaveOptions.DONOTSAVECHANGES); 
     doc.paste(); 
     } catch (e) { 
     // need to skip files Photoshop can't open 
     // could also be done via a file filter 
     continue; 
     } 

    } 

    } 
} 

main(); 
+0

看起來像這樣做,我可以在applescript中做什麼。試圖看看我是否可以避免打開第二個文件。 – 2014-10-06 14:34:42

+0

我認爲鏈接/放置智能對象的選項不會暴露給腳本API。 – fabianmoronzirfas 2014-10-07 09:56:34

0

我一直在尋找同樣的事情。打開所有文件,選擇和複製粘貼內容對最終用戶來說不是一個很好的視覺體驗。

使用Photoshop Scriptlistener plugin,你可以聽動作,並讓他們用JavaScript寫出來。然後您可以重播或修改它們以方便您。

這個(第一行除外)是我用監聽器捕獲的。它會要求您輸入文件並將其放置在當前打開的文檔中。您可以使用此處提供的代碼@fabiantheblind輕鬆修改此情況。

var sourceFile= File.openDialog('pick an image'); 
var idPlc = charIDToTypeID("Plc "); 
var desc3 = new ActionDescriptor(); 
var idnull = charIDToTypeID("null"); 
desc3.putPath(idnull, sourceFile); 
var idFTcs = charIDToTypeID("FTcs"); 
var idQCSt = charIDToTypeID("QCSt"); 
var idQcsa = charIDToTypeID("Qcsa"); 
desc3.putEnumerated(idFTcs, idQCSt, idQcsa); 
executeAction(idPlc, desc3, DialogModes.NO); 

您可以將其粘貼到擴展工具包中,並查看它是否有效。我有它在CC工作,還沒有測試它的cc2014

+0

在試圖放置eps文件時,在OSX上的Photoshop中,此代碼會生成一個錯誤:無法讀取postscript代碼 – rndm 2015-03-19 16:49:18

+0

您應該安裝scriptlistener並在您的文檔中放置一個eps,然後使用scriptlistener記錄的代碼。 Theberrornis可能是因爲放置一個eps需要對其進行光柵化處理,而且您不提供任何選項。 – user3319803 2015-03-19 17:02:15

相關問題