select object and move another one

hello. this is my first post.
excuse me for my english:D

this is my question:
i want create a script that when select the cube then sphere move.

import bpy
def movement():
if bpy.context.active_object.name == “Cube”:
bpy.data.objects[“Sphere”].location[0] +=1
movement()

the problem is that the script only work when I press run script,
how make that the script work whenever select the Cube?

thanks!

strange wish :no:
Your Cube is selected, type: gx1LMB (or Enter i.p.v LMB)

It means you want to activate Python by some, say click on an object?

@ rulflinks - you can easily prepare an endless cycle to run movement() many times in a row. BUT your proc says when the Cube is selected => move the Sphere by 1 unit further. So when you have your Cube selected, your Sphere will run away in less than a second cause your movement() proc will run thousands of time in a second. Of course, some special measures can be taken so that movement() run only when you select Cube, i.e. just once at a selection, a second time at second selection, but you should really think more about if you wish such a great automatization for just moving a sphere 1 unit away?!?!?

Regards,

I want to try make a ik fk autosnap, I want try that when Cube (is a example) is selected the bone constraint influence = 1 or 0 .but whenever the cube is selected the arm is in fk or ik.
the example is to make easy the explanation.
my english is very poor.
thanks for all