Locking an animation window from script?

I’m looking for a way to lock an animation window from an editor script, I don’t mind using reflection, I just can’t seam to find the property that is responsible for that?

I want to open an animation window with a specific animation clip (from script), and keep editing it regardless of the selected object.

Stumble upon this as well, since there is no one answered this yet, here I go.
The mechanic to lock editor window differs from each, inspector or timeline, etc.

For AnimationWindow it will surely require reflection.
Here is the step I managed to assign a clip to AnimationWindow and lock it.
(Unity 2022.3.62f)

First obtain AnimationWindow by any mean:

To find a last active window:
EditorWindow.GetWindow<AnimationWindow>( );
For finding multiple windows, use this:
Resources.FindObjectsOfTypeAll(typeof(AnimationWindow));

Then

     _SetAnimationWindowLocked( animWindow, false );
     _SetAnimationWindowClip( animWindow, animationClip );
     _SetAnimationWindowLocked( animWindow, true );

These are above helper functions:
All of this must be in editor script.

using UnityEditor;
using UnityEngine;
using System.Reflection;

        private static void _SetAnimationWindowClip( AnimationWindow win, AnimationClip clip )
        {
            var funcEditAnimationClip = typeof(AnimationWindow).GetMethod( "EditAnimationClip", BindingFlags.Instance | BindingFlags.NonPublic );
            funcEditAnimationClip.Invoke( win, new object[] { clip } );
        }

        private static void _SetAnimationWindowLocked( AnimationWindow win, bool lockState )
        {
            // Set member m_LockTracker.isLocked = true
            var fieldm_LockTracker = typeof(AnimationWindow).GetField( "m_LockTracker", BindingFlags.Instance | BindingFlags.NonPublic );
            var propisLocked = fieldm_LockTracker.FieldType.GetProperty( "isLocked", BindingFlags.Instance | BindingFlags.NonPublic );

            var lockTrackerInstance = fieldm_LockTracker.GetValue( win );
            propisLocked.SetValue( lockTrackerInstance, lockState );
            win.Repaint( );
        }

This mechanic can be seen/learn/backtrack from Unity CSharp internal reference.

UnityCsReference/Editor/Mono/Animation/AnimationWindow/AnimationWindow.cs at master · Unity-Technologies/UnityCsReference · GitHub

UnityCsReference/Editor/Mono/EditorGUIUtility.cs at master · Unity-Technologies/UnityCsReference · GitHub