Qu’ils mangent de la batchPlay!
const photoshop = require('photoshop') ;
const { app } = photoshop ;
const { batchPlay } = photoshop.action ;
/**
* get indexes for all channels of a document.
* not sure if indexes or indices should be used
* @param {Number} docID target document id
* @return {Promise<Array<Number>>}
*/
const getChannelIndexes = async (docID) => {
const retval = await batchPlay(
[
{
"_obj": "multiGet",
"_target": [
{
"_ref": "document",
"_id": docID
}
],
"extendedReference": [
[
"itemIndex"
],
{
"_obj": "channel",
"index": 1,
"count": -1
}
],
"options": {
"failOnMissingProperty": false,
"failOnMissingElement": false
},
"_options": {
"dialogOptions": "dontDisplay"
}
}
],
{}
) ;
const res = retval[0].list.map((item) => {return item.itemIndex}) ;
return res ;
} ;
/**
* get channel by index
* @param {Number} docID target document id
* @param {Number} index target channel index
* @return {Promise<any>} {channelName: String, itemIndex: Number, count: Number, visible: Boolean, histogram: Array<Number>}
*/
const getChannelByIndex = async (docID, index) => {
const retval = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_ref": "channel",
"_index": index
},
{
"_ref": "document",
"_id": docID
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],
{}
) ;
return retval[0] ;
}
const main = async () => {
const docID = app.activeDocument.id ;
const indexes = await getChannelIndexes(docID) ;
const channels = await Promise.all(indexes.map(async (index) => {
return await getChannelByIndex(docID, index) ;
})) ;
console.log(channels) ;
// --> (3) [{…}, {…}, {…}]
} ;
