Now that you know how to handle object selection, managing objects is straightforward. Like working in the GUI, select an object to rename it:
selectObject: id Rename: "new-name"
or copy it:
selectObject: id Copy: "new-name"
or remove it:
selectObject: id Remove
It's even possible to execute
Info and save the result to a variable:
selectObject: id object_info$ = Info
Then the content of object_info$ could be written to Praat Info, simulating the GUI behavior of the
Info button. Or you can extract interesting chunks using
There's only one new command to be introduced in this section:
removeObject. It's a convenience command supplementing
Remove only selected objects can be removed, with
removeObject objects can be removed directly, without selecting them first. Consider the concatenation script from the previous section:
first_sound = selected ("Sound", 1) second_sound = selected ("Sound", 2) selectObject: second_sound samp_freq = Get sampling frequency sil = Create Sound from formula: "silence", 1, 0, 1, samp_freq, "0" selectObject: second_sound copy = Copy: "tmp" plusObject: sil plusObject: first_sound Concatenate Play selectObject: copy, sil Remove
Two objects are selected in the penultimate line to be removed in the last line. When the script terminates, nothing is selected (because the most recently selected objects don't exist any more). So if the script user wants to listen to the concatenated sound again, two clicks are necessary: the first click to select the object, the second click on the
Play button. The new command
removeObject avoids fiddling with the existing selection (the concatenated sound stays selected), it just removes every specified object:
first_sound = selected ("Sound", 1) second_sound = selected ("Sound", 2) selectObject: second_sound samp_freq = Get sampling frequency sil = Create Sound from formula: "silence", 1, 0, 1, samp_freq, "0" selectObject: second_sound copy = Copy: "tmp" plusObject: sil plusObject: first_sound Concatenate Play # remove objects without selecting them removeObject: copy, sil
Of course, it's possible to imitate this behavior with the help of
removeObject means less typing and better readability.
Acknowledge object selection as an important matter of script development and handle these things with appropriate care.
There are two sides to the object selection issue: (1) script-controlled selection of objects (active), and (2) querying selections made by the script user or the Praat mechanism (reactive).
Two methods are supported to identify objects for script-controlled selection: type+name and ID. You should prefer identification by ID because it's fail-safe, unique, and more comfortable. Redundant object selection is harmless, a missing selection may have serious consequences. Therefore, regarding script-controlled selection, generous is better than parsimonious.
selected () and
selected$ () Praat provides a powerful and complex method to implement fine-grained queries of selections. It's possible to enquire type+name or ID. Most of the time, ID is the better choice. Selections made by the script user before launching the script should be analyzed at the beginning of the script because they tend to be destroyed during runtime.