# Detect when auto keying is turned on/off via Python?

I want to make it VERY obvious when auto keying is turned on in Blender. I want to write an add-on where, if auto keying is turned on, Blender's theme turns to Blender Light. Otherwise, Blender's theme is Blender Dark.

The core of the add-on is basically this:

if bpy.context.scene.tool_settings.use_keyframe_insert_auto == True:
else:


Is it possible -- via an add-on -- to intercept when use_keyframe_insert_auto changes and then have this code execute? If so, how?

If that's not possible, what is the recommended way of handling this?

• Feb 24 '20 at 5:58

You can use a message bus subscription to do that.

The following script will call a function when 'use_keyframe_insert_auto' is changing from the UI.

The principle is:

• Obtain a subscription link using path_resolve on the scene
• Then use this link to subscribe in order to fire a function when the value changes

Here is the code (look at the console to see the printed results):

import bpy

#The callback when use_keyframe_insert_auto changed
def a_callback(scene):
print( scene, "use_keyframe_insert_auto changed" )

def subscribe_to_scene(scene):

#Get a rna subscription link from the scene
subscribe_to = scene.path_resolve("tool_settings.use_keyframe_insert_auto", False)

#Effectively subscribe to the rna path from the scene
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=scene,
args=(scene,),
notify=a_callback,
)

subscribe_to_scene(bpy.context.scene)