• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JavaScripting HSB

New Here ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

Still new to all this.

I'm making script, and as a step I need to shift hue by set amount in recently opened document.

Like this:

Before, just opened

0070019_1_OBP_Happy_Cz.png

After hue shift +80

z.png

I tried to google it, but everything listed doesn't work for me. Currently I just use bit recorded with ScriptListener:

    var idHStr = charIDToTypeID("HStr");

    var desc5 = new ActionDescriptor();

    var idpresetKind = stringIDToTypeID("presetKind");

    var idpresetKindType = stringIDToTypeID("presetKindType");

    var idpresetKindCustom = stringIDToTypeID("presetKindCustom");

    desc5.putEnumerated(idpresetKind, idpresetKindType, idpresetKindCustom);

    var idClrz = charIDToTypeID("Clrz");

    desc5.putBoolean(idClrz, false);

    var idAdjs = charIDToTypeID("Adjs");

    var list1 = new ActionList();

    var desc6 = new ActionDescriptor();

    var idH = charIDToTypeID("H   ");

    desc6.putInteger(idH, 80);

    var idStrt = charIDToTypeID("Strt");

    desc6.putInteger(idStrt, 0);

    var idLght = charIDToTypeID("Lght");

    desc6.putInteger(idLght, 0);

    var idHsttwo = charIDToTypeID("Hst2");

    list1.putObject(idHsttwo, desc6);

    desc5.putList(idAdjs, list1);

    executeAction(idHStr, desc5, DialogModes.NO);

But that's too crude and hard to manage.

I know, that I must set SolidColor, like this:

var NewHue = new SolidColor();

NewHue.hsb.hue = 80;

But I cannot apply it. Well, app says I applied it, but no difference seen.

TOPICS
Actions and scripting

Views

758

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 07, 2017 May 07, 2017

Without to write two lines in one it seems to be that 8 lines are the minimum required code

(desc1 = new ActionDescriptor()).putEnumerated(stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindCustom'))

desc1.putBoolean(stringIDToTypeID('colorize'), false);

(desc2 = new ActionDescriptor()).putInteger(stringIDToTypeID('hue'), 80)

desc2.putInteger(stringIDToTypeID('saturation'), 0)

desc2.putInteger(stringIDToTypeID('lightness'), 0);

(list1 = new ActionList()).pu

...

Votes

Translate

Translate
Adobe
Community Expert ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

Your ScriptListener code works as it is (on every selected artlayer). This means the layer should be selected (and not a layer with a selection). And you don't need a new SolidColor.

Save you code as jsx and run from script menu in PS.

Here is the same code as yours, but only a little bit cleaned

var desc1 = new ActionDescriptor();

desc1.putEnumerated( stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindCustom') );

desc1.putBoolean( charIDToTypeID('Clrz'), false );

    var list1 = new ActionList();

        var desc2 = new ActionDescriptor();

        desc2.putInteger( charIDToTypeID('H   '), 80 );

        desc2.putInteger( charIDToTypeID('Strt'), 0 );

        desc2.putInteger( charIDToTypeID('Lght'), 0 );

    list1.putObject( charIDToTypeID('Hst2'), desc2 );

desc1.putList( charIDToTypeID('Adjs'), list1 );

executeAction( charIDToTypeID('HStr'), desc1, DialogModes.NO );

Have fun

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

I know that it works, script containing it worked just fine.

Now I have to include it in more elaborate algorhitm than before, and this block is very hard to properly maintain.

I hoped that there exists something shorter and more transparent, about 5-6 lines total.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

How good is your Javascript knowledgebase?

You can work with functions. Rewrite the above code as function

function hueCorrection(hue, sat, bright) {

    var desc1 = new ActionDescriptor();

    desc1.putEnumerated( stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindCustom') );

    desc1.putBoolean( charIDToTypeID('Clrz'), false );

        var list1 = new ActionList();

            var desc2 = new ActionDescriptor();

            desc2.putInteger( charIDToTypeID('H   '), hue );

            desc2.putInteger( charIDToTypeID('Strt'), sat );

            desc2.putInteger( charIDToTypeID('Lght'), bright );

        list1.putObject( charIDToTypeID('Hst2'), desc2 );

    desc1.putList( charIDToTypeID('Adjs'), list1 );

    executeAction( charIDToTypeID('HStr'), desc1, DialogModes.NO );

};

Call this function with this line whenever you need it:

hueCorrection(80,0,0);

Have fun

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

Well, little to none, see above.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

Without to write two lines in one it seems to be that 8 lines are the minimum required code

(desc1 = new ActionDescriptor()).putEnumerated(stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindCustom'))

desc1.putBoolean(stringIDToTypeID('colorize'), false);

(desc2 = new ActionDescriptor()).putInteger(stringIDToTypeID('hue'), 80)

desc2.putInteger(stringIDToTypeID('saturation'), 0)

desc2.putInteger(stringIDToTypeID('lightness'), 0);

(list1 = new ActionList()).putObject(stringIDToTypeID('hueSatAdjustmentV2'), desc2);

desc1.putList(stringIDToTypeID('adjustment'), list1)

executeAction(stringIDToTypeID('hueSaturation'), desc1, DialogModes.NO);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

So, that hsb property in ref table is just for show?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

LATEST

No it is not just for show.

You can use it to set the foreground/background colour or a single pixel colour.

You can not use it for an adjustment layer, action manager code is required to do that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 07, 2017 May 07, 2017

Copy link to clipboard

Copied

Try this...

hueLayer(80,0,0);

function hueLayer(hue,sat,bright) {

var desc86 = new ActionDescriptor();

var ref51 = new ActionReference();

ref51.putClass( charIDToTypeID('AdjL') );

desc86.putReference( charIDToTypeID('null'), ref51 );

var desc87 = new ActionDescriptor();

var desc88 = new ActionDescriptor();

desc88.putEnumerated( stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindDefault') );

desc88.putBoolean( charIDToTypeID('Clrz'), false );

desc87.putObject( charIDToTypeID('Type'), charIDToTypeID('HStr'), desc88 );

desc86.putObject( charIDToTypeID('Usng'), charIDToTypeID('AdjL'), desc87 );

try{

executeAction( charIDToTypeID('Mk  '), desc86, DialogModes.NO );

}catch(e){}

var desc89 = new ActionDescriptor();

var ref52 = new ActionReference();

ref52.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('RGB ') );

desc89.putReference( charIDToTypeID('null'), ref52 );

desc89.putBoolean( charIDToTypeID('MkVs'), false );

try{

executeAction( charIDToTypeID('slct'), desc89, DialogModes.NO );

}catch(e){}

var desc90 = new ActionDescriptor();

var ref53 = new ActionReference();

ref53.putEnumerated( charIDToTypeID('AdjL'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

desc90.putReference( charIDToTypeID('null'), ref53 );

var desc91 = new ActionDescriptor();

desc91.putEnumerated( stringIDToTypeID('presetKind'), stringIDToTypeID('presetKindType'), stringIDToTypeID('presetKindCustom') );

var list9 = new ActionList();

var desc92 = new ActionDescriptor();

desc92.putInteger( charIDToTypeID('H   '), hue );

desc92.putInteger( charIDToTypeID('Strt'), sat );

desc92.putInteger( charIDToTypeID('Lght'), bright );

list9.putObject( charIDToTypeID('Hst2'), desc92 );

desc91.putList( charIDToTypeID('Adjs'), list9 );

desc90.putObject( charIDToTypeID('T   '), charIDToTypeID('HStr'), desc91 );

try{

executeAction( charIDToTypeID('setd'), desc90, DialogModes.NO );

}catch(e){}

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines