Set a custom field with a image url by category

Hi, I need set a custom field with a image url by category.

I have created a function to set a diferent image URL by category, finally I add the "update_post_meta" function. My code: http://pastebin.com/7EnMExUS

I think that I need add this function to an action. In fact, I don't know how to get this work :smiley:

Best regards