skip to Main Content

I need to group a few images into one photoshop file and try to look for a more optimized path. I know I can use applescript to do something like this.

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

I can use the open to open every image one at a time and move it into one document. My Question is, does anyone have some better way to place images directly into the open document. Looking for the effect of just dragging an image in. I am open to having a javascript function to do it. (I don’t know javascript but I can manage to mostly understand what I read.)

2

Answers


  1. I wrote it in ExtendScript.
    Tested on 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();
    
    Login or Signup to reply.
  2. I’ve been looking for the same thing. Opening all the files, selecting and copy-pasting the content is not a really good visual experience for the end-user.

    Using the Photoshop Scriptlistener plugin, you can listen to actions and have them written out for you in javascript. You can then replay or modify them to your convenience.

    This (except the first line) is what I’ve captured with the listener. It asks you for a file input and places it in the current open document. You can easily modify this to your situation using the code @fabiantheblind provided here.

    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 );
    

    You can paste this in extendscript toolkit and see that it works. I have it working in CC, haven’t tested it for cc2014

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search