Scripting: Best way to time shift a track

Hi !

I am trying to time shift a selected track using scripting commands in Python, ideally the shift would be for a given number of ms.
I am selecting the time shifting tool and then what ?

Here is my main code (the do_command() works fine) :

do_command("Import2: Filename=C:\Users\…\track1.wav ")
do_command(“Import2: Filename=C:\Users\…\track2.wav”)
do_command(‘SelectTracks: Track=2’)

What next ?

Thank you for your help ! :slight_smile:

I don’t think it’s possible to do “mouse drag” from Python, so you need to approach this a different way.

If you want to move a clip to the right, make a selection to the left of the clip (or at the start of the clip) and duplicate it. If the original selection was empty space, then you’re done. If the original selection was audio, then go back to that selection and silence it.

To move a clip to the left, just make a selection to the left of the clip, and delete it.

Thanks for the answer !
I am not quite sure that it exactly match my need. I will try to make it clearer:

I have two tracks (track1, track2).
I want to make a *.py function with “x” as input that:

. load the wav files

. move track2 of “x” ms to the right

. play

Is that possible with Audacity scripting ?

Thanks again,

  1. Select “x” ms at the start of track 2.
  2. Repeat (1 time)
  3. Select “x” ms at the start of track 2
  4. Silence (or “Split Delete”)

Step to is the “Repeat effect” and that will shift the track to the right by “x” ms.
The final step may be either the Silence effect, or “Split Delete” or “Split Cut”. The former will leave “x” ms of silence at the start. The latter 2 will leave “x” ms of empty space at the start.

Nice ! Good trick, it worked perfectly. THANK YOU !