Reading the label colors from preferences file

Explorer ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

Hey,

I am trying to read the label colors from the "Adobe After Effects 18.0 Prefs-indep-general.txt" file. This is how it looks in the file:

["Label Preference Color Section 5"]
   "Label Color ID 2 # 1" = FFB5"88"
   "Label Color ID 2 # 10" = FF8E","9A
   "Label Color ID 2 # 11" = FFE8920D
   "Label Color ID 2 # 12" = FF7F"E*"
   "Label Color ID 2 # 13" = FFF4"m"D6
   "Label Color ID 2 # 14" = FF"="A2A5
   "Label Color ID 2 # 15" = FFA896"w"
   "Label Color ID 2 # 16" = FF1E"@"1E
   "Label Color ID 2 # 2" = FFE4D8"L"
   "Label Color ID 2 # 3" = FFA9CBC7
   "Label Color ID 2 # 4" = FFE5BCC9
   "Label Color ID 2 # 5" = FFA9A9CA
   "Label Color ID 2 # 6" = FFE7C19E
   "Label Color ID 2 # 7" = FFB3C7B3
   "Label Color ID 2 # 8" = FF"g}"E0
   "Label Color ID 2 # 9" = FF"J"A4"L"

 

I tried accessing the first color by using this code:

 

var sectionName = "Label Preference Color Section 5", keyName = "Label Color ID 2 # 1";
var prefFile = PREFType.PREF_Type_MACHINE_INDEPENDENT;
var mypref = app.preferences.getPrefAsString(sectionName, keyName, prefFile);
alert(mypref); // empty string

 

I also tried:

 

var mypref = app.preferences.getPrefAsLong(sectionName, keyName, prefFile);
alert(mypref); // 0
var mypref = app.preferences.getPrefAsFloat(sectionName, keyName, prefFile);
alert(mypref); // 0
var mypref = app.preferences.getPrefAsBool(sectionName, keyName, prefFile);
alert(mypref); // true

 

 Trying to get it from the settings object also returned an empty string: 

app.settings.getSetting(sectionName, keyName, prefFile).
 
I was able to access other preferences (the label name, for example) by doing that, but it doesn't work with the colors. Also, the hex codes in the prefs.txt file look a little weird, does anyone know why they are written that way?
 
Thanks!
TOPICS
Scripting

Views

568

Likes

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

Adobe Community Professional , Apr 03, 2021 Apr 03, 2021
Okay, this table seems to work for ASCII-extended characters. No garuntees, but looks like it checks out with the current colors. Built the table from this table https://theascii.com/extended-ascii-table/ var table1252 = { "€":128, "‚":130, "ƒ":131, "„":132, "…":133, "†":134, "‡":135, "ˆ":136, "‰":137, "Š":138, "‹":139, "Œ":140, "Ž":142, "‘":145, "’":146, "“":147, "”":148, "•":149, "–":150, "—":151, "˜":152, "™":153, "š":154, "›":155, "œ":156, "ž":158, "Ÿ":159, "¡":161, "¢":162, "£":163, "¤":1...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

A few steps are required.  (updated)

 

// Encoding must be default
$.appEncoding = 'CP1252'

var sectionName = "Label Preference Color Section 5", keyName = "Label Color ID 2 # 1";
var prefFile = PREFType.PREF_Type_MACHINE_INDEPENDENT;
var mypref = app.preferences.getPrefAsString(sectionName, keyName, prefFile);

// mypref is now ÿµ88 
var srcStr = mypref.toSource(); // (new String("\u00FF\u00B588"))
var res = srcStr.match(/\"(.*)\"/)[0].replace(/\"/g, '').replace(/\\\u00/g, '')

alert(res); // FFB588

 

 

Likes

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
Explorer ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Thank you so much, it works perfectly! But do you know how can I get the hex code from Preferences > Labels > Label Colors (in your example it would be B53838)? Thanks for the help!

Likes

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
Adobe Community Professional ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Sorry, that was a typo in the comment, the result should be the correct hex code FFB588.

Likes

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
Adobe Community Professional ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Nevermind, I see what you're saying. That's not the correct hex code for color 1 red. It should be B53838, not FFB588.

 

Okay, I think looping through each char and converting them to hex should do the trick:

 

// Encoding must be default
$.appEncoding = 'CP1252'

var sectionName = "Label Preference Color Section 5", keyName = "Label Color ID 2 # 1";
var prefFile = PREFType.PREF_Type_MACHINE_INDEPENDENT;
var mypref = app.preferences.getPrefAsString(sectionName, keyName, prefFile);

var res = '';
for (var i = 1; i < mypref.length; i++) {
    var charCode = mypref.charCodeAt(i)
    res += charCode.toString(16).toUpperCase();
}
alert(res); // B53838

 

 

Likes

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
Explorer ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Oh, I didn't see your comment. That's perfect, thank you so much!

Likes

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
Explorer ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

The result is FFB588, but what I'm looking for is the hex code you see in the preferences (not the preferences .txt file, the ones in the AE interface). In the .txt file the hex code is FFB588, but in the preferences menu in AE it's B53838. It shouldn't be that complicated to find the right hex code, but I just can't figure out how to do it.

Likes

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
Adobe Community Professional ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Yea, the issue is there are 4 characters resulting ARGB (alpha, red, green, blue). We can disregard the first Alpha since it'll always be 100% or FF. So as you see the 2nd example I posted above, jumps to the 2nd character through the 4th character to get the RGB values and converts them to hex.

Likes

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
Explorer ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Oh, I see. Thank you for your help, you saved me a lot of frustration...

Likes

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
Explorer ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Hey Justin, I just noticed your solution from yesterday works in most cases, but not every time. In the default labels 4 of them return the wrong hex code:

function getLabelsFromPrefs(){
  $.appEncoding = 'CP1252';

  var sectionName = "Label Preference Color Section 5";
  var prefFile = PREFType.PREF_Type_MACHINE_INDEPENDENT;
  var keyName;
  var mypref;
  var resArray = [];

  for(var i = 1; i <= 16; i++){
    keyName = "Label Color ID 2 # " + i.toString();
    mypref = app.preferences.getPrefAsString(sectionName, keyName, prefFile);

    var res = '';
    for(var j = 1; j < mypref.length; j++) {
        var charCode = mypref.charCodeAt(j)
        res += charCode.toString(16).toUpperCase();
    }
    resArray.push(res);
  }
    return resArray;
};

// B53838, E4D84C, A9CBC7, E5BCC9, A9A9CA, E7C19E, B3C7B3, 677DE0, 4AA44C, 8E2C9A, E8920D, 7F452A, F46DD6, 3DA2A5, A89677, 1E401E

alert(
"B53838 - " + getLabelsFromPrefs()[0] + " - " + (getLabelsFromPrefs()[0] === "B53838") + "\n"+
"E4D84C - " + getLabelsFromPrefs()[1] + " - " + (getLabelsFromPrefs()[1] === "E4D84C") + "\n"+
"A9CBC7 - " + getLabelsFromPrefs()[2] + " - " + (getLabelsFromPrefs()[2] === "A9CBC7") + "\n"+
"E5BCC9 - " + getLabelsFromPrefs()[3] + " - " + (getLabelsFromPrefs()[3] === "E5BCC9") + "\n"+
"A9A9CA - " + getLabelsFromPrefs()[4] + " - " + (getLabelsFromPrefs()[4] === "A9A9CA") + "\n"+
"E7C19E - " + getLabelsFromPrefs()[5] + " - " + (getLabelsFromPrefs()[5] === "E7C19E") + "\n"+ // false
"B3C7B3 - " + getLabelsFromPrefs()[6] + " - " + (getLabelsFromPrefs()[6] === "B3C7B3") + "\n"+
"677DE0 - " + getLabelsFromPrefs()[7] + " - " + (getLabelsFromPrefs()[7] === "677DE0") + "\n"+
"4AA44C - " + getLabelsFromPrefs()[8] + " - " + (getLabelsFromPrefs()[8] === "4AA44C") + "\n"+
"8E2C9A - " + getLabelsFromPrefs()[9] + " - " + (getLabelsFromPrefs()[9] === "8E2C9A") + "\n"+ // false
"E8920D - " + getLabelsFromPrefs()[10] + " - " + (getLabelsFromPrefs()[10] === "E8920D") + "\n"+ // false
"7F452A - " + getLabelsFromPrefs()[11] + " - " + (getLabelsFromPrefs()[11] === "7F452A") + "\n"+
"F46DD6 - " + getLabelsFromPrefs()[12] + " - " + (getLabelsFromPrefs()[12] === "F46DD6") + "\n"+
"3DA2A5 - " + getLabelsFromPrefs()[13] + " - " + (getLabelsFromPrefs()[13] === "3DA2A5") + "\n"+
"A89677 - " + getLabelsFromPrefs()[14] + " - " + (getLabelsFromPrefs()[14] === "A89677") + "\n"+ // false
"1E401E - " + getLabelsFromPrefs()[15] + " - " + (getLabelsFromPrefs()[15] === "1E401E")
);

 Any idea what might be causing this issue? Thanks!

Likes

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
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Hmm, okay so this is trickier than I thought. So turns out converting with charCodeAt() gets the ASCII value, but while the prefs file is UTF-8 encoded, the color strings are in CP1252 or Windows-1252 encoding.

 

For example the character "ž" in ASCII is 382, which is out of scope for 0-255, while the Windows-1252 value is 158, the correct value.

 

You can test this by going to https://www.rapidtables.com/convert/number/ascii-to-hex.html

and selecting "Windows-1252" in character encoding, pasting the value for "Label Color ID 2 # 6" "ÿçÁž" and the result it will give you is correct: "ff e7 c1 9e".

 

The issue now is that I'm not aware of a built-in way to convert that with extendScript. I found a library online that works with node.js, so we would either need to find an ES3/ExtendScript compatible library for this conversion, or roll our own.

 

Also, looks like you're not the first one to run into this issue, found a few other similar threads without a definitive result:

 

https://community.adobe.com/t5/after-effects/color-labels/td-p/5644065

https://community.adobe.com/t5/after-effects/get-label-colors-from-pref/td-p/7716338

https://community.adobe.com/t5/after-effects/convert-the-ascii-color-code-to-hex/m-p/11197128

 

One alternative solution for values that are beyond 255, is to read the txt file and build your own parser, but I think finding or building a converter table of some sort would be the best approach.

 

Likes

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
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Okay, this table seems to work for ASCII-extended characters. No garuntees, but looks like it checks out with the current colors. Built the table from this table https://theascii.com/extended-ascii-table/

 

var table1252 = {
"€":128,
"‚":130,
"ƒ":131,
"„":132,
"…":133,
"†":134,
"‡":135,
"ˆ":136,
"‰":137,
"Š":138,
"‹":139,
"Œ":140,
"Ž":142,
"‘":145,
"’":146,
"“":147,
"”":148,
"•":149,
"–":150,
"—":151,
"˜":152,
"™":153,
"š":154,
"›":155,
"œ":156,
"ž":158,
"Ÿ":159,
"¡":161,
"¢":162,
"£":163,
"¤":164,
"¥":165,
"¦":166,
"§":167,
"¨":168,
"©":169,
"ª":170,
"«":171,
"¬":172,
"�­":173,
"®":174,
"¯":175,
"°":176,
"±":177,
"²":178,
"³":179,
"´":180,
"µ":181,
"¶":182,
"·":183,
"¸":184,
"¹":185,
"º":186,
"»":187,
"¼":188,
"½":189,
"¾":190,
"¿":191,
"À":192,
"Á":193,
"Â":194,
"Ã":195,
"Ä":196,
"Å":197,
"Æ":198,
"Ç":199,
"È":200,
"É":201,
"Ê":202,
"Ë":203,
"Ì":204,
"Í":205,
"Î":206,
"Ï":207,
"Ð":208,
"Ñ":209,
"Ò":210,
"Ó":211,
"Ô":212,
"Õ":213,
"Ö":214,
"×":215,
"Ø":216,
"Ù":217,
"Ú":218,
"Û":219,
"Ü":220,
"Ý":221,
"Þ":222,
"ß":223,
"à":224,
"á":225,
"â":226,
"ã":227,
"ä":228,
"å":229,
"æ":230,
"ç":231,
"è":232,
"é":233,
"ê":234,
"ë":235,
"ì":236,
"í":237,
"î":238,
"ï":239,
"ð":240,
"ñ":241,
"ò":242,
"ó":243,
"ô":244,
"õ":245,
"ö":246,
"÷":247,
"ø":248,
"ù":249,
"ú":250,
"û":251,
"ü":252,
"ý":253,
"þ":254,
"ÿ":255
};

function getLabelsFromPrefs(){
  $.appEncoding = 'CP1252';

  var sectionName = "Label Preference Color Section 5";
  var prefFile = PREFType.PREF_Type_MACHINE_INDEPENDENT;
  var keyName;
  var mypref;
  var resArray = [];

  for(var i = 1; i <= 16; i++){
    keyName = "Label Color ID 2 # " + i.toString();
    mypref = app.preferences.getPrefAsString(sectionName, keyName, prefFile);

    var res = '';
    for(var j = 1; j < mypref.length; j++) {
            var charCode = mypref.charCodeAt(j);
    if(charCode > 254){
        charCode = table1252[mypref[j]]
    }
    var newCode = charCode.toString(16).toUpperCase();
    if(newCode.toString().length === 1){
        newCode = '0'+newCode;
    }
    // alert(mypref[i] +' is '+charCode)
        res += newCode;
    }
    resArray.push(res);
  }
    return resArray;
};

// B53838, E4D84C, A9CBC7, E5BCC9, A9A9CA, E7C19E, B3C7B3, 677DE0, 4AA44C, 8E2C9A, E8920D, 7F452A, F46DD6, 3DA2A5, A89677, 1E401E

alert(
"B53838 - " + getLabelsFromPrefs()[0] + " - " + (getLabelsFromPrefs()[0] === "B53838") + "\n"+
"E4D84C - " + getLabelsFromPrefs()[1] + " - " + (getLabelsFromPrefs()[1] === "E4D84C") + "\n"+
"A9CBC7 - " + getLabelsFromPrefs()[2] + " - " + (getLabelsFromPrefs()[2] === "A9CBC7") + "\n"+
"E5BCC9 - " + getLabelsFromPrefs()[3] + " - " + (getLabelsFromPrefs()[3] === "E5BCC9") + "\n"+
"A9A9CA - " + getLabelsFromPrefs()[4] + " - " + (getLabelsFromPrefs()[4] === "A9A9CA") + "\n"+
"E7C19E - " + getLabelsFromPrefs()[5] + " - " + (getLabelsFromPrefs()[5] === "E7C19E") + "\n"+ 
"B3C7B3 - " + getLabelsFromPrefs()[6] + " - " + (getLabelsFromPrefs()[6] === "B3C7B3") + "\n"+
"677DE0 - " + getLabelsFromPrefs()[7] + " - " + (getLabelsFromPrefs()[7] === "677DE0") + "\n"+
"4AA44C - " + getLabelsFromPrefs()[8] + " - " + (getLabelsFromPrefs()[8] === "4AA44C") + "\n"+
"8E2C9A - " + getLabelsFromPrefs()[9] + " - " + (getLabelsFromPrefs()[9] === "8E2C9A") + "\n"+ 
"E8920D - " + getLabelsFromPrefs()[10] + " - " + (getLabelsFromPrefs()[10] === "E8920D") + "\n"+ 
"7F452A - " + getLabelsFromPrefs()[11] + " - " + (getLabelsFromPrefs()[11] === "7F452A") + "\n"+
"F46DD6 - " + getLabelsFromPrefs()[12] + " - " + (getLabelsFromPrefs()[12] === "F46DD6") + "\n"+
"3DA2A5 - " + getLabelsFromPrefs()[13] + " - " + (getLabelsFromPrefs()[13] === "3DA2A5") + "\n"+
"A89677 - " + getLabelsFromPrefs()[14] + " - " + (getLabelsFromPrefs()[14] === "A89677") + "\n"+ 
"1E401E - " + getLabelsFromPrefs()[15] + " - " + (getLabelsFromPrefs()[15] === "1E401E")
);

 

Likes

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
Explorer ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

It's perfect! it's working great with the default colors, and I'll let you know if I find any issues with other colors. Thank you so much for all your help, I really appreciate it!

Likes

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
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Awesome, glad to hear it!

Likes

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
Participant ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

I hope it's ok to revive this thread from april, but I'm working on something that needs exactly what you did here - to read the current set label colors. But I'm going a step further and add the names of the colors to the mix. I've added this function to the code above (mostly blatant copy paste):

 

function getLabelNamesFromPrefs() {
$.appEncoding = 'CP1252';

  var sectionName2 = "Label Preference Text Section 5";
  var prefFile2 = PREFType.PREF_Type_MACHINE_INDEPENDENT;
  var keyName2;
  var mypref2;
  var resArray2 = [];

  for(var i = 1; i <= 16; i++){
    keyName2 = "Label Text ID 2 # " + i.toString();
    mypref2 = app.preferences.getPrefAsString(sectionName2, keyName2, prefFile2);
    resArray2.push(mypref2);
    }
    return resArray2;
}



alert(
getLabelsFromPrefs()[0] + " - "+getLabelNamesFromPrefs()[0]+"\n" + 
getLabelsFromPrefs()[1] + " - "+getLabelNamesFromPrefs()[1]+"\n" + 
getLabelsFromPrefs()[2] + " - "+getLabelNamesFromPrefs()[2]+"\n" + 
getLabelsFromPrefs()[3]  + " - "+getLabelNamesFromPrefs()[3]+"\n" + 
getLabelsFromPrefs()[4]  + " - "+getLabelNamesFromPrefs()[4]+"\n" + 
getLabelsFromPrefs()[5]  + " - "+getLabelNamesFromPrefs()[5]+"\n" + 
getLabelsFromPrefs()[6]  + " - "+getLabelNamesFromPrefs()[6]+"\n" +  
getLabelsFromPrefs()[7]  + " - "+getLabelNamesFromPrefs()[7]+"\n" + 
getLabelsFromPrefs()[8]  + " - "+getLabelNamesFromPrefs()[8]+"\n" +  
getLabelsFromPrefs()[9] + " - "+getLabelNamesFromPrefs()[9]+"\n" + 
getLabelsFromPrefs()[10]  + " - "+getLabelNamesFromPrefs()[10]+"\n" + 
getLabelsFromPrefs()[11]  + " - "+getLabelNamesFromPrefs()[11]+"\n" +  
getLabelsFromPrefs()[12]  + " - "+getLabelNamesFromPrefs()[12]+"\n" + 
getLabelsFromPrefs()[13]  + " - "+getLabelNamesFromPrefs()[13]+"\n" + 
getLabelsFromPrefs()[14]  + " - "+getLabelNamesFromPrefs()[14]+"\n" +  
getLabelsFromPrefs()[15] + " - "+getLabelNamesFromPrefs()[15] 
);

 

The output is fine so far:

 

CorvinusCorax_0-1624532051939.png

 

The HEX Values are also updated in the alert when custom values are entered in AE. Changes on HEX and Names are also reflected in the Prefs-indep-general file.

 

Sadly, the names stay the same in the alert. Any idea, what I'm doing wrong?

 

 

 

Likes

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
Participant ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

Nevermind, found it out by myself - it should read Section 7, not Section 5. Seems that Section 5 is a list of the default values:

 

  var sectionName2 = "Label Preference Text Section 7";

Likes

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
Explorer ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Can you share a link to the library you found? And yeah, hopefully somebody will find a solution to this problem soon.

Likes

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
Participant ,
Apr 21, 2022 Apr 21, 2022

Copy link to clipboard

Copied

LATEST

Hey! Here's how I deal with it in my CEP Panel:

https://github.com/GoodBoyNinja/Get-Layers-Label-Colors-using-CEP

Likes

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