fabianmoronzirfas
10/21/2014 - 9:11 AM

import files to Photoshop

import files to Photoshop

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

    var main = function(arguments, body) {
      // filter does not work on OSX
      if (app.documents.length < 1) {
        // abort no file to place imports in
        return;
      }
      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();