将图像放入当前打开的photoshop文档中(appescription)

Placing an image into a currently open photoshop document (applescript)

本文关键字:文档 photoshop appescription 图像      更新时间:2023-09-26

我需要将一些图像分组到一个photoshop文件中,并尝试寻找一个更优化的路径。我知道我可以用苹果来做这样的事。

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,但我能大致理解我读到的内容。)

我是用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();

我一直在寻找同样的东西。对于最终用户来说,打开所有文件、选择并复制粘贴内容并不是一种很好的视觉体验。

使用Photoshop Scriptlistener插件,您可以监听操作并用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 );

您可以将其粘贴到extendscript工具包中,并查看它是否有效。我在CC中工作过,还没有在cc2014 中测试过它