Grease Pencil selection in Dopesheet via python

I would like to switch GP layer to draw on While I am in drawmode by choosing the layer in Dopesheet(gp). (The selected layer may be in a different GPObject so choosing from Drawmode right now does not work) (this feature has been requested a year ago in community… no success)

So maybe it can be done in python?
But in order to do that, the system would need to exit drawmode to object mode, select the correct GPobject with the intended layer, go back into Drawmode.
I would like to make a script to do this based on what is highlighted in Dopesheet(GP)

I need assistance on how to find the dopesheet info and what in the tree is selected via Python.

Any help is appreciated.

thank you

import bpy
context = bpy.context

gpencils = [ob for ob in context.view_layer.objects if ob.type == 'GPENCIL']
for gpencil in gpencils:
    selected_layers = [layer for layer in gpencil.data.layers if layer.select]
    if selected_layers:
        active_pencil = gpencil
        active_layer = selected_layers[0]
        break

if context.object != active_pencil:
    if context.mode == 'PAINT_GPENCIL':
        bpy.ops.object.mode_set(mode='OBJECT')
        
    context.object.select_set(False)
    active_pencil.select_set(True)
    context.view_layer.objects.active = active_pencil
    bpy.ops.object.mode_set(mode='PAINT_GPENCIL')
    active_pencil.data.layers.active = active_layer