Get/Setting color profile of a document

Hello.

What’s the best way to get or set a color profile for a document? Is this possible without using BatchPlay?

Cheers.

//get profile

async function getProfile() {

     const batchPlay = require("photoshop").action.batchPlay;

     const result = await batchPlay(

       [{

         "_obj": "get",

         "_target": [{

           "_property": "json",

           "Int8Array": "json"

         },

         {

           "_ref": "document",

           "_enum": "ordinal",

           "_value": "targetEnum"

         }

         ],

         "_options": {}

       }], {});



     let risultato = result[0].json

     return JSON.parse(risultato)}

     getProfile().then(function(x){colorprofile=x.profile})

console.log(colorprofile)

//assign profile

var profile=“Adobe RGB (1998)”

async function assignProfile(profile){

const batchPlay = require(‘photoshop’).action.batchPlay

const result = await batchPlay(

[

{

"_obj": "assignProfile",

"_target": [

 {

  "_ref": "document",

  "_enum": "ordinal",

  "_value": "targetEnum"

 }

],

"profile": profile,

"_isCommand": true,

"_options": {

 "dialogOptions": "dontDisplay"

}

}

],{

“synchronousExecution”: false,

“modalBehavior”: “fail”

});}
//convert profile

async function convertProfile(profile){

  const batchPlay = require('photoshop').action.batchPlay 

  const result = await batchPlay( 

  [ 

  {

   "_obj": "convertToProfile",

   "_target": [

    {

     "_ref": "document",

     "_enum": "ordinal",

     "_value": "targetEnum"

    }

   ],

   "to": profile,

   "intent": {

    "_enum": "intent",

    "_value": "colorimetric"

   },

   "mapBlack": true,

   "dither": true,

   "flatten": false,

   "rasterizePlaced": false,

   "shadowMode": -1,

   "_isCommand": true,

   "_options": {

    "dialogOptions": "dontDisplay"

   }

  }

  ],{ 

  "synchronousExecution": false, 

  "modalBehavior": "fail" 

  });}

i don’t know if there is a way without batchplay

1 Like

Thanks a lot. I was just wondering if there is a solution outside of BatchPlay. It seems as if there are a lot less functions in UXP than there are in CEP and pretty much every advanced operation has to be created via BatchPlay. So far it’s a bit of a struggle to get my plugin converted to UXP. There’s still a lot do improve with this API. But at least the UXP Developer Tool is really nice and speeds things up a bit.

Cheers.

The PS DOM API is very young at this point. More and more APIs will be coming over the upcoming Ps versions that will increase the API surface, but for now, batchPlay is the escape hatch for missing features in the PS DOM API.

1 Like

Yeah - I understand. But considering that you already deactivate CEP support on some systems, resulting in existing extensions not working any more, this is a bit of a lukewarm transition. New things should not be weaker than the predecessor. Also the Spectrum implementation is sad. When you look at the Web Spectrum documentation you are initially impressed, but so little of all that can be used at this point. And the documentation is in line with the rest - very sparse and unfinished. And thank heavens that somebody wrote the Alchemist plugin. Without that, this all would be impossible.

I will get to the end somehow - but this takes way more time and tricks than it should have to for a “great, new” system.

EDIT: I just saw that even a basic function like “resizeImage” isn’t fully or properly implemented. No example on how to resize proportionally or how to use the resample method. I guess another case for BatchPlay.