composite mode, use the Z of a named object.

Is it somehow possible to do defocus based on what the camera has in focus (an object).
I see there is no scripting input, and for movie making this would be nice.
Since adjusting defocus for each frame is a little bit to much work.

Select an object for the camera focus distance


Connect the render Z pass to the defocus node and enable the ‘Use Z-Buffer’ option

hm it doesnt seam to work, i have an object and like your picture i always set focus like that, but defocus doesnt folow the object
it seams more that defocus uses the general Z image, and based on that does defocus, which one can oly change with a math node