# How to execute python code before blender operator is executed

Lets say there are operators (buttons .etc) that run or save the text in Text Editor. I need to change the text before such operators execute.

Is there a way involving some callback functions, listeners or handlers?

If there is not, is there a way to remove UI element and replace it in the same spot with custom operator? I only found a way how to append or prepend an operator to such menu or header.

• I cant change the source code, this must work from addon. So I can only change it like: bpy.types.TEXT_HT_header.prepend(foo). The difficult part is to remove the old entry and place a new one in that spot. – Jaroslav Jerryno Novotny Dec 4 '14 at 11:55