Skip to main content
Alan_AEDScripts
Inspiring
December 9, 2013
Question

Color Labels

  • December 9, 2013
  • 2 replies
  • 4957 views

What kind of data are label colors being saved as in prefs ?

I know this was discussed in a post but can't find the exact post....

Thanks

Alan.

"Label Color ID 2 # 1" = FFB60505

          "Label Color ID 2 # 10" = FF8E","9A

          "Label Color ID 2 # 11" = FFC8"~"0C

          "Label Color ID 2 # 12" = FF7F"E*"

This topic has been closed for replies.

2 replies

zsaaro
Inspiring
April 21, 2022
Legend
December 10, 2013

I would assume string given that prefs can be saved or retrieved via these methods:

app.preferences

     .deletePref()

     .getPrefAsBool()

     .getPrefAsFloat()

     .getPrefAsLong()

     .getPrefAsString()

     .havePref()

     .reload()

     .savePrefAsBool()

     .savePrefAsFloat()

     .savePrefAsLong()

     .savePrefAsString()

     .saveToDisk()

Alan_AEDScripts
Inspiring
December 11, 2013

Thanks David, but I am trying to figure out how the colours are represented in these strings, don't recognise the data format...

thanks.

Alan_AEDScripts
Inspiring
April 18, 2016

Sorry for upping an old thread.

Alan, have you succeed with the whole decoding stuff and made it readable?


function changeColPref(num,r,g,b){

    var sect = "Label Preference Color Section 5";

    var key = "Label Color ID 2 # " + num.toString();

    var thePref = app.preferences.getPrefAsString(sect,key);

    //for reading

    function hexToRgb(str) {

        if ( /^#([0-9a-f]{3}|[0-9a-f]{6})$/ig.test(str) ) {

            var hex = str.substr(1);

            hex = hex.length == 3 ? hex.replace(/(.)/g, '$1$1') : hex;

            var rgb = parseInt(hex, 16);

            return 'rgb(' + [(rgb >> 16) & 255, (rgb >> 8) & 255, rgb

& 255].join(',') + ')';

        }

        }

    function ascii2hex(str) {

      var arr = [];

      for (var i = 0, l = str.length; i < l; i ++) {

        var hex = Number(str.charCodeAt(i)).toString(16);

        arr.push(hex);

      }

        return arr.join('');

        }

    //for writing

    function hex2Ascii(hex) {

        var str = '';

        for (var i = 0; i < hex.length; i += 2)

            str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));

        return str;

        }

    function rgbToHex(r,g,b) {

        var out = '';

        //Adobe expects 4Chars, first one is always...

        for (var i = 0; i < 3; ++i) {

            var n = typeof arguments == 'number' ? arguments :

parseInt(arguments);

            if (isNaN(n) || n < 0 || n > 255) {

                return false;

            }

            //out+=" %" // so we decode  %22 %56 %99 - spaces between.

            out += (n < 16 ? '0' : '') + n.toString(16);

        }

        alert(out);

        return "FF"+out;  //#171717

        }

    var newCol = rgbToHex(r,g,b);

    var newColAscii = hex2Ascii(newCol);

    app.preferences.savePrefAsString(sect,key,newColAscii);

    app.preferences.saveToDisk();

    app.preferences.reload();

}//close change pref.

changeColPref(1,5,199,252);

This is the code that I used a few years ago, so have not looked at it since... perhaps you can muddle through it and see if it works with CC . . .