Scripting 9.1. Turning a script into a stand-alone program

You can turn your script into a double-clickable stand-alone program by including it into Praat's main procedure. If you want to try this, you should already know how to compile and link the Praat program on your computer.

These stand-alone programs do not show the Objects window and the Picture window; therefore, you will usually want to use Demo window commands in your script. Here is an example:

#include "praat.h"

const char32 myScript [ ] = U""
    "demo Text: 0.5, \"centre\", 0.5, \"half\", \"Hello world\"\n"
    "demoWaitForInput ( )\n"
;

int main (int argc, char *argv [ ]) {
    praat_setStandAloneScriptText (myScript);
    praat_init (U"Hello", argc, argv);
    INCLUDE_LIBRARY (praat_uvafon_init)
    praat_run ();
    return 0;
}

The script in this example raises the Demo window, writes "Hello world" in the middle of the window, waits until the user clicks the mouse or presses a key, and then closes.

Note that Praat is distributed under the General Public License (GPL). This means that if you distribute a Praat-based stand-alone program, you have to make it open source under the GPL as well.

See also Programming with Praat.

Details

Your program can save its preferences in a directory of its choice, e.g. in 'preferencesDirectory$'/../GuineaPigAnalyzer if your program is called GuineaPigAnalyzer. If you want to be less conspicuous and like to use the Praat preferences directory instead, please use the apps subdirectory, in this way:

createDirectory: preferencesDirectory$ + "/apps"
createDirectory: preferencesDirectory$ + "/apps/GuineaPigAnalyzer"

Links to this page


© ppgb, July 13, 2015