Scripting 8.1. The sendpraat subroutine

A subroutine for sending messages to a running Praat. Also a Unix, MacOS, or DOS console program with the same purpose.

Syntax

sendpraat (void *display, const char *program, long timeOut, char *text);

Arguments

display
the display pointer if the subroutine is called from a running X program; if NULL, sendpraat will open the display by itself. On Windows and Macintosh, this argument is ignored.
program
the name of a running program that uses the Praat shell, e.g. "Praat" or "ALS". The first letter may be specified as lower or upper case; it will be converted to lower case for Unix and to upper case for Macintosh and Windows.
timeOut (Unix and Macintosh only)
the number of seconds that sendpraat will wait for an answer before writing an error message. A timeOut of 0 means that the message will be sent asynchronously, i.e., that sendpraat will return immediately without issuing any error message.
text
the script text to be sent. Sendpraat may alter this text!

Example 1: killing a program

char message [100], *errorMessage;
strcpy (message, "Quit");
errorMessage = sendpraat (NULL, "praat", 0, message);
if (errorMessage != NULL) fprintf (stderr, "%s", errorMessage);

This causes the program Praat to quit (gracefully), because Quit is a fixed command in one of the menus of that program. On Unix and Macintosh, sendpraat returns immediately; on Windows, the timeOut argument is ignored. The return value errorMessage is a statically allocated string internal to sendpraat, and is overwritten by the next call to sendpraat.

Example 2: playing a sound file in reverse

Suppose you have a sound file whose name is in the variable fileName, and you want the program Praat, which can play sounds, to play this sound backwards.

char message [1000], *errorMessage;
sprintf (message, "Read from file... %s\nPlay reverse\nRemove", fileName);
errorMessage = sendpraat (NULL, "praat", 1000, message);

This will work because Play reverse is an action command that becomes available in the dynamic menu when a Sound is selected. On Unix, sendpraat will allow Praat at most 1000 seconds to perform this.

Example 3: executing a large script file

Sometimes, it may be unpractical to send a large script directly to sendpraat. Fortunately, the receiving program knows the execute directive:

char message [100], *errorMessage;
strcpy (message, "execute doAll.praat 20");
errorMessage = sendpraat (NULL, "praat", 0, message);

This causes the program Praat to execute the script doAll.praat with an argument of "20".

How to download

You can download the source code of the sendpraat subroutine and program via www.praat.org or from http://www.fon.hum.uva.nl/praat/sendpraat.html.

See also

To start a program from the command line instead and sending it a message, you would not use sendpraat, but instead run the program with a script file as an argument. See Scripting 6.9. Calling from the command line.

Links to this page


© ppgb, October 20, 2009