In 2.8, you can use message bus to do that:
The principle is to obtain the path using a path name through the object.
Then declare a subscription to message bus.
import bpy
#The callback when then change occurs
def a_callback(object, data):
print( object, data, "changed" )
def subscribe_to(object,data_path,callback):
#Get a rna subscription link from the object
subscribe_to = object.path_resolve(data_path, False)
#Effectively subscribe to the rna path from the object
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=object,
args=(object,data_path,),
notify=callback,
)
subscribe_to(bpy.context.object,"mode", a_callback)
Note: bpy.msgbus is not documented for now. But it contains few functions that we can find using the Python console:
