# How to trigger something when selecting a bone?

Basically this, but with bones instead of objects.

Bones seem to be way more complex than objects. This is what I tried to do but it doesn't work and I have no idea why.

import bpy

def bone_callback():
print('Bone "{}" was selected'.format(bpy.context.object.data.bones.active))

def subscribe_to_bone(selected_bone):
subscribe_to = bpy.types.ArmatureBones, "active"

bpy.msgbus.subscribe_rna(
key = subscribe_to,
owner = selected_bone,
args = (selected_bone,),
notify = bone_callback,
)

subscribe_to_bone(bpy.context.object.data.bones.active)