Skip to main content
Participant
April 9, 2009
Question

Scripting Hue/Saturation

  • April 9, 2009
  • 1 reply
  • 1361 views

I can't figure out how to adjust the saturation from AppleScript!?!? (Or Javascript)

I am about to create an Action that adjusts the saturation and simply invoke that, but it feels wrong.

Help!

This topic has been closed for replies.

1 reply

MarkWalsh
Inspiring
April 9, 2009

Use script listener:

// =======================================================

var id14 = charIDToTypeID( "HStr" );

    var desc4 = new ActionDescriptor();

    var id15 = charIDToTypeID( "Clrz" );

    desc4.putBoolean( id15, false );

    var id16 = charIDToTypeID( "Adjs" );

        var list1 = new ActionList();

            var desc5 = new ActionDescriptor();

            var id17 = charIDToTypeID( "H   " );

            desc5.putInteger( id17, hueAdjustmentValue);

            var id18 = charIDToTypeID( "Strt" );

            desc5.putInteger( id18, saturationAdjustmentValue );

            var id19 = charIDToTypeID( "Lght" );

            desc5.putInteger( id19, lightnessAdjustmentValue );

        var id20 = charIDToTypeID( "Hst2" );

        list1.putObject( id20, desc5 );

    desc4.putList( id16, list1 );

executeAction( id14, desc4, DialogModes.NO );

replace your values for hueAdjustmentValue, saturationAdjustmentValue & lightnessAdjustmentValue

Participant
April 9, 2009

Thank you for pointing me to the ScriptListener system! Hadn't heard of that before. To make it work in AppleScript I simply grabbed the resulting javascript code and put it in a "do javascript" command... after converting the double quotes to single quotes.

do javascript "var id35 = charIDToTypeID( 'HStr' );

    var desc6 = new ActionDescriptor();

    var id36 = charIDToTypeID( 'Clrz' );

    desc6.putBoolean( id36, false );

    var id37 = charIDToTypeID( 'Adjs' );

        var list1 = new ActionList();

            var desc7 = new ActionDescriptor();

            var id38 = charIDToTypeID( 'H   ' );

            desc7.putInteger( id38, 0 );

            var id39 = charIDToTypeID( 'Strt' );

            desc7.putInteger( id39, 27 );

            var id40 = charIDToTypeID( 'Lght' );

            desc7.putInteger( id40, 0 );

        var id41 = charIDToTypeID( 'Hst2' );

        list1.putObject( id41, desc7 );

    desc6.putList( id37, list1 );

executeAction( id35, desc6, DialogModes.NO );

"

Excellent! I will use this again for other "unscriptables!"

Participant
April 9, 2009

If it will help someone else coding AppleScript, here is my AppleScript abstraction of the Hue/Saturation/Lightness javascript...

on PS_AdjustHueSaturationLightness(h, s, l)

tell application "Adobe Photoshop CS3"

tell document 1

do javascript "

    var desc6 = new ActionDescriptor();

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

        var list1 = new ActionList();

            var desc7 = new ActionDescriptor();

            desc7.putInteger( charIDToTypeID( 'H   ' ), " & h & " );

            desc7.putInteger( charIDToTypeID( 'Strt' ), " & s & " );

            desc7.putInteger( charIDToTypeID( 'Lght' ), " & l & " );

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

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

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

"

end tell

end tell

end PS_AdjustHueSaturationLightness