About Object Selection
Working in the Praat GUI you select single items in the objects list of Praat Objects by clicking with the mouse. Multiple objects are selected by SHIFT-clicks or CTRL-clicks (Mac: CMD-clicks). It is mandatory to simulate this behavior in scripts since scripts utilize GUI commands and GUI commands affect only selected objects. At least, this is important for scripts running in the shell environment. Scripts running in an editor environment don't have to worry about object selection because editor GUI commands affect always the object which is edited.
Supplementing user controlled object selection Praat provides a built-in selection mechanism: If a new object is created it is automatically selected (and everything else is deselected!). It is very important to keep this in mind while writing scripts. If your script handles multiple objects and/or creates or removes objects, be attentive and be sure to verify frequently whether the statements in the script really address the desired objects. To illustrate the importance of this point, consider this statement:
Get sampling frequency
Monitoring and controling
object selection is important!
If you made sure that the correct sound object is addressed (i.e. is selected at the time the statement is executed) everything is fine. If, by accident, a spectrum object is addressed an error message will pop up, which is also fine because you can react. But if, by a more fatal accident, the wrong sound object is addressed there's no error message, so you'll never know that you queried a false value and the results of your script may be seriously corrupted. In conclusion, you should really acknowledge object selection as an important matter of script development and handle these things with appropriate care.
Selecting an already selected object has no consequences.Next: Making Selections
Accidentally querying the wrong object often has serious consequences.
In the worst case results will be corrupted!