# Find key in Property List based on value

**URL:** <https://forums.eggplantsoftware.com/t/find-key-in-property-list-based-on-value/3221>\
**Category:** Eggplant Functional\
**Created:** [January 30, 2013, 4:25pm UTC](https://forums.eggplantsoftware.com/t/find-key-in-property-list-based-on-value/3221 "2013-01-30T16:25:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jswanson](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@jswanson](https://forums.eggplantsoftware.com/u/jswanson)\
**Post date:** [January 30, 2013, 4:25pm UTC](https://forums.eggplantsoftware.com/t/find-key-in-property-list-based-on-value/3221/1 "2013-01-30T16:25:30Z")

</div>

It is probably a simple syntax problem but I am not able to retrieve a Key name from a property list.

I am using a background RGB value to identify a particular Color Scheme a user has selected. I created a property list of a schema name to RGB values. i.e. (Navy:(0,0,140), etc). I have a script to capture the coloratlocation for a background color value. I do a "if input is in RGBtable then return the schema name.  
This script finds the RGB value in table but I do not know how to return the key name.

---

<div class="post-metadata">

**Author:** ![RyanD](https://forums.eggplantsoftware.com/user_avatar/forums.eggplantsoftware.com/ryand/32/94_2.png) [@RyanD](https://forums.eggplantsoftware.com/u/RyanD)\
**Post date:** [January 30, 2013, 6:52pm UTC](https://forums.eggplantsoftware.com/t/find-key-in-property-list-based-on-value/3221/2 "2013-01-30T18:52:26Z")

</div>

You can iterate over all the keys in your list and find which key’s value matches the value you are looking for. For example:

set foo to (a:1, b:2, c:3)  
repeat with each item of foo’s keys  
if 2 equals foo.(it) then put it  
end repeat

In this case the key ‘b’ is printed.

---

<div class="post-metadata">

**Author:** ![jswanson](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@jswanson](https://forums.eggplantsoftware.com/u/jswanson)\
**Post date:** [January 31, 2013, 1:48pm UTC](https://forums.eggplantsoftware.com/t/find-key-in-property-list-based-on-value/3221/3 "2013-01-31T13:48:07Z")

</div>

I tried your example and even used lists and it worked fine

However when I used the example as a template for my script I did not get the results I expected. I think the problem now lies with how lists are passed between functions

put ColorAtLocation(x,y) into RGB

fum.foo RGB \<- is this the correct syntax to pass a list

to foo fooRGB  
log fooRGB \<- 2,45,100 is displayed not (2,45,100)  
set foo to (a: (1,45,33), b: (2,45,100), c: (3,23,130))  
repeat with each item of foo’s keys  
if 2 equals foo.(it) then  
put it into SeeIt  
end if  
end repeat  
log SeeIt \<- nothing shows up  
end foo

I can count items in fooRGB and display a single item if I want to but when I do the comparison to the property list values no match is ever found

---

<div class="post-metadata">

**Author:** ![SenseTalkDoug](https://forums.eggplantsoftware.com/user_avatar/forums.eggplantsoftware.com/sensetalkdoug/32/88_2.png) [@SenseTalkDoug](https://forums.eggplantsoftware.com/u/SenseTalkDoug)\
**Post date:** [January 31, 2013, 2:45pm UTC](https://forums.eggplantsoftware.com/t/find-key-in-property-list-based-on-value/3221/4 "2013-01-31T14:45:32Z")

</div>

The way you are passing the value is fine. In this case the value you are passing is a color, so its representation is controlled by the colorFormat global property, which by default will present the color as a text string (like “2,45,100” in your case).

For your test you could either put all of your comparison values in this same format, like this:

```auto
set foo to (a:"1,45,33", b:"2,45,100", c:"3,23,130")

```

or, you can ask SenseTalk to compare colors rather than text. Doing it this way will allow the colors being compared to be in any of the dozen or so color formats (including named colors) that SenseTalk understands. Your comparison would then look something like this:

```auto
if the color of fooRGB equals foo.(it) as color then
  put it into SeeIt
end if

```

This works because whenever SenseTalk knows that two values are both colors, it will compare them as colors, regardless of what format they are in. Using “the color of” or “as color” are two ways to ensure that those values are treated as colors.
