Is there a simple list of options one can use with "do_command"?

I have been looking throughout the scripting guides supplies by Audacity but they all seem to describe options that are normally activated in audacity menu items. They are not in any kind of format that can be used in scripting.

I accidentally entered "do_command(“NEW”) which opens a new track if Audacity is open. Also: "do_command(“Close”) which closes Audacity. I have spent at lease an hour looking for any other commands to use.

At the moment, I need to program creating a label, naming a label, Start and end record.

Is there a list?
Can someone send the do-command for the ones I listed?

I assume that you are referring to “do_command” from “”?
That Python script is really only intended for testing (as the name suggests). To build a Python app that will do something useful, I’d suggest using the “” module.

Here’s a direct link to is fully documented - open it in your favourite text / code editor to read the docstrings.

If you’ve not used before, I’d suggest that you try the command line interface first (also a good way to test individual commands).

There’s a full list of supported commands in the Audacity manual here:
(The easy way to get to that page is from the “All Commands” link in the “Reference” section in the left column of each page of the manual)

After making three corrections in the command line interface code, I finally got it to work. I can now see a request to enter Q to quit and it works. I also see that a READ_NAME and a WRITE_NAME files have been added to my folder and are empty.

Then I looked at the scripting URL and it sent me right back to the same page that has not made sense all along. I see not one example on how to create the command. In the test program, I saw the “do_command” line and guessed to use “NEW” and “Close”. It worked. No information from the scripting docs helped. I probably have to keep on digging.

“I assume that you are referring to “do_command” from “”?
That Python script is really only intended for testing (as the name suggests). To build a Python app that will do something useful, I’d suggest using the “” module.”

Well, I was able to achieve the execution of two commands using and none with command line interface program from github.

This is starting to look like “Why do it in 65 lines of code when 298, with significant rework, will do?”

Again, I find that “do_command(New)” and “do_command(close)” work in the test program.
All I want is the do-command lines for record, stop, create label, name label.
Can anyone help me?

I have finally managed to get two commands to work but only because I guessed how to use them.
do_command(NEW) where I can open a new track and
do_command(Close) where I can close Audacity.

I still need a command for Record, Stop recording, create label, and name a label.
Guesses gleaned from the audacity scripting page are not helping.

Can you help me?

What were they?

How about Play, Stop, SelectAll, Record1stChoice, Record2ndChoice, or other commands from Scripting Reference - Audacity Manual

1, and 2) Both references to opening the text files need to have quotes around the file name. Near line 160, and line 209.

  1. The program is going to crash until “WRITE_NAME” file exists. I would add code to see if it exists then, if it doesn’t, create it.

How do I have a track record for a specific duration?
I found
do_command(" ‘Start Time’ = 0, ‘End Time’ = 1")
but it fails. I believe as syntax error, command missing.

I don’t know what you mean.
Lines 158 to 166:

    def _write_pipe_open(self):
        """Open _write_pipe."""
        self._write_pipe = open(WRITE_NAME, 'w')

    def _read_thread_start(self):
        """Start read_pipe thread."""
        read_thread = threading.Thread(target=self._reader)
        read_thread.daemon = True

Lines 208 to 211:

        while pipe_ok:
            line = read_pipe.readline()
            # Stop timer as soon as we get first line of response.
            stop_time = time.time()

If “WRITE_NAME” file does not exist, “_write_pipe_open” will wait until it does, but that is non-blocking because it is a separate thread. “_write_thread_start” will then throw an error: “PipeClientError: Write pipe cannot be opened.”

“WRITE_NAME” is the “pipe” that allows Python to connect to Audacity (Named pipe - Wikipedia). It must be created by Audacity. If Python creates it, then it’s just a file, not a pipe into Audacity.

  1. Start the recording
  2. After the specified time, send the “Stop:” command.

Forgive me, I cannot believe how much I screwed up on this one. I have three very large programs that I am working on almost simultaneously. I am linking python to Audacity, python to Excel, and a huge code in python to help me manage my insulin. All three are receiving code that is new to me.

I responded to what I thought was in error in the pipe_test not realizing that the open call was using a variable instead of a file name and “corrected” it accordingly. I made it all worse by posting the mix up.

What’s more, I then opened a different browser, attempted to log in and messed up the password enough times that I became locked out and had to use captcha numerously to get back on. YUCK…

Ok, for fear of the worst, I have made significant head way getting python to talk to Audacity.

Unless someone can suggest why the is not a good choice, I plan to use it unless shown otherwise. It is short, simple, and is performing the way I want.

The loop runs as I want except for one command.

while T < 5:

T += 1
t = str(T)

print(" Track name " + t + " = " + ThisList[T])
do_command(“AddLabel: Text = ThisList[T]”)

print(" Done")

As it is, this program will generate five tracks of 10 second recordings.
Each track will have blank labels.

Eventually, T will be 23 and time.sleep(10) will be an hour.
Right now, t = 5 and sleep is 10 seconds.
I would like to have the label for each track reflect the ThisList[T] entry in the list.
The ThisList list contains 4 letter codes for each entry.

What is wrong with my AddLabel command?
Is there a different way to do this?

(Apparently a file with a .py extension will not attach. yes?)

You will be able to attach it by adding “.txt” to the file name. For example: “”

Your label command:

"AddLabel: Text = ThisList[T]"

but the manual says:

AddLabel: > - (Action) Add Label at Selection - (Parameters) > none > - (Description) Creates a new, empty label at the cursor or at the selection region.

“Text =” is not a valid argument (parameter), because “AddLabel:” does not take any arguments.

You will need to create an empty label (with “AddLabel:”) and then add the text to the label with “SetLabel: Label=[label number] Text=[label text]”.
For example, this will create a point label “Hello” at time = 5 seconds, and a region label “World” from 15 to 16 seconds.

SelectTime:End="5" RelativeTo="ProjectStart" Start="5"
SetLabel:Label="0" Text="Hello"
SelectTime:End="16" RelativeTo="ProjectStart" Start="15"
SetLabel:Label="1" Text="World"

(Note that double quotes, if used, will probably need to be escaped in your script)

SelectTime:End=“5” RelativeTo=“ProjectStart” Start=“5”
SetLabel:Label=“0” Text=“Hello”
SelectTime:End=“16” RelativeTo=“ProjectStart” Start=“15”
SetLabel:Label=“1” Text=“World”

This doesn’t seem to work for me. I would like to send the code to Audacity using do_command code. I am still experimenting with the program because it is short and has worked up until now. Maybe I do have to use the other program.
Insights welcome.

What’s happening?

Perhaps worth trying the commands using pipeclient’s command line interface - by default, it prints Audacity’s response to each command, so you can see immediately if a command fails.

This is what I get:


Oop. sorry for the lame entry.
I get the track note but no wording in the label.
It is as if all I did was hit ^b.
No “Hello” and no “World”.

Does your project already have some labels? If it does, then the label index number will not be correct in
SetLabel:Label=“0” Text=“Hello”

If you’re using “”, you will need to escape the double quotes:

"SetLabel:Label=\"0\" Text=\"Hello\""

Have you tried from the command line with pipeclient? Can you reproduce my results if you start with a new, empty project?

I will explore pipeclient but it may take a while to report back. I have two other large projects taking stage.
P.S., I did try the "" escapes in the line but still no text being sent to the label. So close…