I think what your looking for is the Sequencer Scripting Plugin, make sure to enable this in ‘Edit > Plugins’. than you should be able to do something like this…