I am working with the Audacity mod-script-pipeline to write a script which goes through every clip of every track, and gets the name of each track.
My code works with everything except getting the track name, I can’t figure out how to fetch this string using any of the scripting references in the documentation online:
https://manual.audacityteam.org/man/scripting_reference.html
My below code works for everything except getting the trackname, and I launch it with python3 script.py -a 3
# python vin
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import requests
import json
import time
import re
import random
'''
Audacity mod-script-pipeline setup
'''
if sys.platform == 'win32':
print("pipe-test.py, running on windows")
TONAME = '\\.\pipe\ToSrvPipe'
FROMNAME = '\\.\pipe\FromSrvPipe'
EOL = 'rn'
else:
print("pipe-test.py, running on linux or mac")
TONAME = '/tmp/audacity_script_pipe.to.' + str(os.getuid())
FROMNAME = '/tmp/audacity_script_pipe.from.' + str(os.getuid())
EOL = 'n'
print("Write to "" + TONAME +""")
if not os.path.exists(TONAME):
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
sys.exit()
print("Read from "" + FROMNAME +""")
if not os.path.exists(FROMNAME):
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
sys.exit()
print("-- Both pipes exist. Good.")
TOFILE = open(TONAME, 'w')
print("-- File to write to has been opened")
FROMFILE = open(FROMNAME, 'rt')
print("-- File to read from has now been opened toorn")
'''
Audacity Functions
'''
# Send a single command to audacity mod-script-pipeline
def send_command(command):
#print("Send: >>> n"+command)
TOFILE.write(command + EOL)
TOFILE.flush()
# Return the command response
def get_response():
result = ''
line = ''
while line != 'n':
result += line
line = FROMFILE.readline()
return result
# Send one command, and return the response
def do_command(command):
send_command(command)
response = get_response()
#print("Rcvd: <<< n" + response)
return response
'''
#############################################
Start processing command line args
#############################################
'''
# auto -a "number of tracks"
if '-a' in sys.argv:
numberOfTracksIndex = sys.argv.index('-a')
numberOfTracks = int(sys.argv[numberOfTracksIndex+1])
print(f"Export {numberOfTracks} tracks")
# Unmute all tracks
print("Go to first track")
do_command('FirstTrack')
time.sleep(1)
trackCount = 0
while(trackCount < numberOfTracks):
print("nMoves the cursor to the start of the selected track.")
do_command('CursTrackStart')
do_command('CursSelStart')
time.sleep(1)
print(f"Select track: {trackCount}")
do_command(f'SelectTracks: Track={trackCount}')
time.sleep(3)
###### Getting trackname here #######
# Get trackname
print("Get track name:")
nameRsp = do_command('GetInfo: Type="Tracks"')
print("name = ")
print(nameRsp)
trackName = "apple"
# Select clips in this track
maxClips = 3
i = 1
while i <= maxClips:
print(f"select clip {i}")
do_command('SelNextClip')
time.sleep(2)
print("export audio")
i += 1
trackCount += 1
This is the code that gets the track names:
###### Getting trackname here #######
# Get trackname
print("Get track name:")
nameRsp = do_command('GetInfo: Type="Tracks"')
print("name = ")
print(nameRsp)
trackName = "apple"
But my line do_command('GetInfo: Type="Tracks"')
always returns an empty string.
How can I edit my python code to get the track names such as my highlight “apple” text in this image? Thanks