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

Color Labels

Engaged ,
Dec 09, 2013 Dec 09, 2013

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*"

TOPICS
Scripting
4.3K
Translate
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
Advocate ,
Dec 10, 2013 Dec 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()

Translate
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
Engaged ,
Dec 11, 2013 Dec 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.

Translate
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
Advocate ,
Dec 11, 2013 Dec 11, 2013

Ah, gotcha. They look encoded somehow, instead of hex values. I was getting strange results retrieving them with getPrefAsString().

Translate
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
Engaged ,
Dec 11, 2013 Dec 11, 2013

Hey David, was chatting with Kevin Schires...

It's preceeded with FF, then a Hex. Some characters in quotes need to be  converted to URL encoding - but there is still some

funky stuff going on with them, going to experiment a bit more with them tomorrow.

Translate
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
Advocate ,
Dec 11, 2013 Dec 11, 2013

Good to know. If I get some free time, I'll try some more tests.

Translate
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
Engaged ,
Dec 19, 2013 Dec 19, 2013

David, got to the bottom of this...

  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;

        }

So it is saving the values in Ascii format characters.

So using RGB-HEX-ASCII  and vice vearsa solves the issue.

I can now recode a couple of scripts to access the settings -

(when I have a minute to myself that is !)

Translate
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
Engaged ,
Dec 19, 2013 Dec 19, 2013

Thanks for this Alan - very useful to know. I too was puzzled by this!

Anyone know the reason for this encoding, when other strings are human readable?

Christian

Translate
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
Advocate ,
Dec 19, 2013 Dec 19, 2013

Nicely done Alan. Great info to have. Not sure of the reason behind ASCII instead of a straight forward HEX, but there are many odd things behind the coding doors of Adobe.

Translate
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
Enthusiast ,
Apr 06, 2016 Apr 06, 2016

Sorry for upping an old thread.

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

Translate
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
Engaged ,
Apr 07, 2016 Apr 07, 2016

Hi Alex... RGB-HEX-ASCII was the conversion process...  not at desk this wk but if you google a couple of functions to translate the characters...2 steps.   tested it a long time ago with a color picker and it worked.

Translate
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
Engaged ,
Apr 18, 2016 Apr 18, 2016

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 . . .

Translate
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
Enthusiast ,
Apr 18, 2016 Apr 18, 2016

Alan, thank you very much!

To make things work in newer version we need only to add PREFType.PREF_Type_MACHINE_INDEPENDENT

To:

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

and

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

Translate
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
Enthusiast ,
Apr 28, 2016 Apr 28, 2016

Well, yeah.

It doesn't work in AE since CC (maybe CC14 or CC12) versions because

app.preferences.getPrefAsString(sect,key);

is broken there and it gives corrupted values, so you can write values, but can't read them.

Translate
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 ,
Dec 01, 2017 Dec 01, 2017

Has anyone found a workaround for this? I'm getting the "could not convert Unicode characters" error when calling app.preferences.getPrefAsString() on color label values.

Translate
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
Enthusiast ,
Dec 02, 2017 Dec 02, 2017

Unfortunately, there is no workaround so far.

Translate
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
Advocate ,
Dec 06, 2017 Dec 06, 2017

There is a nasty workaround - you have to read prefs file as a text document, parse it and get those values as strings. It's stupid, but that's the only way around that error.

Translate
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
Engaged ,
Apr 04, 2019 Apr 04, 2019

This is what I got to work with AE16.1 (Apr 19)

function asciiToRGB(str) { 

    var arr = []; 

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

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

    arr.push(parseInt(hex, 16)/65533); 

    } 

    return arr; 

}

var colours = [];

for (var i = 1; i <= 16; i++){

    var sect = "Label Preference Color Section 5"; 

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

    var prefType = PREFType.PREF_Type_MACHINE_INDEPENDENT

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

    colours[i-1] =  asciiToRGB(thePref);

}

This is just for reading the label colours, I haven't worked out the writing side, but I'm guessing it will just be the reverse.

Translate
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
Engaged ,
Apr 04, 2019 Apr 04, 2019

Ahh, close, but no biscuit. It works for some of the colours, but not for others.

@Adobe, please tell us how the label colours are encoded in the prefs, or make the RGB label values accessible to scripting somehow. It's so frustrating.

Translate
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
Advocate ,
Apr 05, 2019 Apr 05, 2019

Be careful when reading label colors from preferences with app.preferences.getPrefAsString(sect, key,  prefType) as AE might (and most likely) throw error Unable to parse Unicode Character (or something similar). I'm saying this from experience - I am getting this error all the time on Mac.

What is that 65533 value you are using?

As a side note, Label colors are stored in a mixed ASCII and HEX format. Values in quotes represent printable ASCII characters (32 to 127 in decimal, or 20 to 7E in hex) from the Standard ASCII table. Other values, that fall into Extended ASCII table, are left as hex values.

Translate
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
Contributor ,
Apr 21, 2022 Apr 21, 2022
LATEST
Translate
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