I would like to launch Audacity from Python and open multiple wav files simultaneously

Hello,

I’m trying to write a python script which loads Audacity with multiple audio files in the same window. So far I have been able to do this but instead of opening both audio files on the same window, 2 independent Audacity windows are opened , one for each audio file. Is there a way to do this? See my code below

import subprocess

Opening files in A and B files in Audacity

original_mic_file = “A.wav”
cleaned_mic_file = “B.wav”

if os.name == ‘nt’: # Windows
audacity_path = “C:\Program Files\Audacity\audacity.exe”
subprocess.Popen([audacity_path, original_mic_file,cleaned_mic_file])

Use a LOF file

Bingo!!! I was not aware of the existence of LOF files. I solved my problem with the code below

# Opening files in priFile and mic file in Audacity
original_mic_file = "A.wav"
cleaned_mic_file = "B.wav"

if os.name == 'nt':  # Windows  
    audacity_path = "C:\\\\Program Files\\\\Audacity\\\\audacity.exe"  

    # Creating LOF file for Audacity to open  
    script_directory = os.path.dirname(os.path.abspath(\__file_\_))  
    lof_file_name = os.path.join(script_directory, "audacity_load_files.lof")  
    try:  
        with open(lof_file_name, "w") as f:  
                f.write("window\\n")  
                f.write(f'file "{ original_mic_file}"\\n')  
                f.write(f'file "{ cleaned_mic_file }"\\n')  
        print(f"Successfully created {lof_file_name} with the names of the audio files.")  
    except Exception as e:  
        print(f"An error occurred while creating the .lof file: {e}")                

    subprocess.Popen(\[audacity_path, lof_file_name\])