GetInfo from python script

I use audacity 2.3.1 alpha with mode_pipe enabled and playing with
I’ve looked into scripting docs, maybe using GetInfo I can obtain the following information:
original file imported in audacity, with full path
track name
Can someone give me an example for the commands I must use?
(the text I must send on the pipe)


There’s no direct way to obtain the file name and path of the last imported file from Audacity.
If you are using Python with mod-script-pipe, then you can use Python to do the import, so the exact file name and path is known to Python.

To get track info (including track names) in JSON format:

GetInfo: Type=Tracks

To get labels in JSON format:

GetInfo: Type=Labels

Example output:

  [ 1,
      [ 23.8822, 23.8822, "Hello" ],
      [ 87.568, 108.308, "World" ] ] ] ]

thanks, steve,
it works perfect

and the last unknowns for me:
Is there a way I get can the label time already formatted like the selection times appear on the bottom of the window?
Can I get the start and end of a selection ?


The command:

GetInfo: Type=Labels

will return something like this:

  [ 1,
      [ 1, 2, "Hello" ],
      [ 5, 6, "World" ] ] ] ]
BatchCommand finished: OK

So the first thing to do is to extract the JSON part of the output string - that is, the text up to the final “]”.
That will give you something like:

  [ 1,
      [ 1, 2, "Hello" ],
      [ 5, 6, "World" ] ] ] ]

which can be parsed by json.loads("<json-string-to-decode>") to give an array in the form:

[[1, [[1, 2, "Hello"],  [5, 6, "World"]]]]

The array contains an array, and the second (n=1) item in the inner array is the label data that we want.
So, if the decoded data is “jdata”, the array of labels is

labels = jdata[0][1]

Putting it all together:

In this example, I’m using (

import sys
import json
import time

import pipeclient

client = pipeclient.PipeClient()

client.write('GetInfo: Type=Labels')

# Allow a little time for Audacity to return the data:
reply = (
if reply == '':
    sys.exit('No data returned.')

# For robust code, the 'reply' string should be validated,
# but in this example I just assume that it is OK.
jdata = (reply [:reply.rfind(']')+1])

# Parse the jason data string:
data = json.loads(jdata)

# Extract the labels:
    labels = data[0][1]
except IndexError:
    sys.exit('No labels found.')

for label in labels:

thanks a lot for all your help