Attempting to writing a script to lock/unlock all audio tracks

Hi All you Python Geniuses,
I am extremely new to Python, so I’m 100% not sure what I’m doing, but I’m having fun trying to figure it out as I go.
Basically, I was getting really sick of manually locking and unlocking all my audio tracks, I know shift click works on video tracks but I couldn’t find anything comparable on the audio side. I have a script that works as long as I have the specific sequence selected in the media panel (thanks to Fred Warren’s delete empty tracks script).
Where I am having trouble and would love some guidance is, rather than have the script be based on what is selected in the media panel, I’m trying to have it reference the current sequence in the timeline window and manipulate its tracks. I’m able to have it pop up as a custom timeline ui but nothing happens. Below is one of the many iterations I’ve failed at with.

Thank you all for whatever help you can offer. (2.7 KB)

If you are using Flame 2023 or up you could replace the section under “Timeline Does Not Work” with:

    import flame

    for audio_track in flame.timeline.clip.audio_tracks:
        for channel in audio_track.channels:
            if len(channel.segments) == 1:
                channel.locked = True

The key is the usage of flame.timeline.clip which is a shortcut to the clip currently displayed in the Timeline. This is the part that is new as of Flame 2023.

If you are using an older version…

First you need to know that it is not possible to pass a PyTrack or PyVersion as the selection. Only a PySegment, PyTransition (2023), PyTimelineFX or PyMarker. You could submit an Improvement Request to have PyTrack/PyVersion added to this list.


  1. Change PyTrack for PySegment in scope_track at the top
  2. Change the content of the “Timeline Does Not Work” section for:
    import flame

    clip = selection[0].parent.parent.parent

    for audio_track in clip.audio_tracks:
        for channel in audio_track.channels:
            if len(channel.segments) == 1:
                    channel.locked = True

The key here is to use the multiple .parent to go up back to the PySequence level.

Hi Fred,
Thanks so much for a quick response. I’m running Flame 2023.0.1 and for some reason I couldn’t get the flame.timeline.clip technique to work, but the selection[0].parent etc worked like a charm. At one point I had the thinking of using .parent but I clearly was going too far or not far enough.
Thanks for your help.