The whole BatchPlay approach is definitely much more self-explaining if you already had contact with Action Manager code in CEP panels, as it’s just like a better version of it with less required syntax.
So don’t get discouraged, the beginning of learning it is difficult but once the concept get’s more clearer you see a lot of recurring patterns. Essentially, you send directions to Photoshop (for example set or get some objects/property) that get assigned to a specific element like the active Document or the layer at index 23 etc. (that’s the _ref part or the BatchPlay object)
I agree that more code examples would be helpful for certain scenarios, I’m sure now that UXP is public there will be a lot more examples and open-source repos coming in the next weeks & months.
For your specific scenario, it’s helpful to just inspect the available properties in Alchemist. You can either browse through the property dropdown and see what properties are there or add the descriptor for the whole document (without a property selected) and browse through the tree-content in the main view on the right.
You can click the pin icon in this view to pin a single property. If you go to the generated code, it will respect the pin and adjust the code:
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_ref": "document",
"_id": 271
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
const pinned = result[0].mode;
If you already select the property from the dropdown, only the mode property will be fetched:
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_property": "mode"
},
{
"_ref": "document",
"_id": 271
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
The results are the same, but the second approach has better performance since not all other document properties will be fetched, only the mode property.
If you log the result from the above code, you will see that it’s an array of objects (descriptors), where the first has the property mode:

So you can’t use it as is, instead you get the mode via
result[0].mode
Also note, that the generated Code references the document by its ID. If you want to reuse the code, you should alter this part to reference the active document, otherwise your code will only work on this specific document. Also, for getters it’s fine to set the synchronousExecution to true, because you’ll want to wait for the result anyway:
function getDocumentMode() {
const batchPlay = require("photoshop").action.batchPlay;
return batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_property": "mode"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": true,
"modalBehavior": "fail"
})[0].mode;
}
Many properties in Photoshop don’t just come as the value, instead it’s incapsulated in an
{
_enum: …
_value: …
}
object.
So here’s an example of how to log the mode as a string:
console.log(getDocumentMode()._value)