# Automate save as shapekey for multiple animation actions

I have a model with a armature with several animation actions in it, these actions are facial expressions, and i'm converting each action to a shape key using the "save as shapekey" option in the armature modifier for the model, there are two ways that i'm doing this manually

First way is selecting the armature > selecting the action > selecting the model > save as shape key > repeat

The other way i can do this manually is creating copies of the armature + mesh > selecting a different action for each armature copie > select all models > go to the shape key tab for one of the models > join as shapes

I have been looking for a way to automate one these tasks with python, or if there is a easier way to do this within blender

i wasn't able to find a way to fully automate the task but was able to streamline and reduce the time it takes to complete it using this sequence in the command recorder addon Nascent Space suggested, from about 15 minutes to less than 2, so i'm satisfied

bpy.context.view_layer.objects.active = bpy.data.objects['M_Head']
bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=True, modifier="md_chr0305_2064_hq")
bpy.context.view_layer.objects.active = bpy.data.objects['md_chr0305_2064_hq']
bpy.ops.object.posemode_toggle()
bpy.ops.pose.select_all(action='SELECT')
bpy.ops.pose.transforms_clear()
bpy.ops.object.posemode_toggle()