BatchPlay Action references not working properly

Hi all :wave:
I have been using batch play to save a specific file via _target field. But it seems operating on the active document.
Here is my batchplay:
image
Here is the result:


Here is my code:

    const result = await Photoshop.app.batchPlay([
      {
        _obj: "save",
          as: {
            _obj: "photoshop35Format",
          },
          in: {
            _path: fileToken,
            _kind: "local"
          },
          _target: {
            _ref: 'document',
            _id: sourceFileId,
          },
          copy: true,
          lowerCase: true,
          _options: {
            dialogOptions: "dontDisplay"
          }
        }
      ], {});

Thank you

Sadly that is the problem for many actions. You could try DOM instead batchPlay. It should take care of it automatically.

1 Like

@Jarda, any plans to fix this? Currently I activate the document I need and then do the action :confused:

As far, as I know it is more like on “nice things to have” kind of list. So quite a low priority so far. But otherwise, I have no influence over this anymore.

@Jarda I have some file types that need to be saved that DOM does not support. Hopefully BatchPlay _target will be fixed soon. Thank you so much

I see. It’s sad to hear that actual bug fix is just nice to have :frowning:

Or, add a document selection (by ID) descriptor object in the batchPlay() array first, and remember to select back the old one after.
Like:

const activeID = app.activeDocument.id;
batchPlay([
  { _obj: "select", _target: [{ _ref: "document", _id: <whateverIDtheDocumentHas>}] },
  { /* your save descriptor */},
  { _obj: "select", _target: [{ _ref: "document", _id: activeID}] },
])

Feel free to select by ID, offset, name, whatever.
I’m writing this without testing, so I might have typos all over the place, but you should get the gist of it.
This is what the DOM internally does with some secret sauce, but the general idea is the same.
HTH,
—Davide

That’s exactly what I do currently, but that should not be the case. Otherwise document ID doesn’t even matter in such cases, even though some identifier is mandatory