Remember the script below from the session on command history:
Create Sound as pure tone: "tone", 1, 0, 0.4, 44100, 440, 0.2, 0.01, 0.01 Play Edit Zoom in Zoom in Zoom in Zoom in
This script terminates in line 4 with an error message. The reason is that the script runs in what is called the Praat shell and the Praat shell doesn't know about the command
Zoom in. The Praat shell is only aware of GUI commands available in Praat Objects and Praat Picture. Praat Objects and Praat Picture are the primary components of the Praat GUI, everything else you can do with Praat you'll start either in Praat Objects or Praat Picture. That's why these two windows are displayed when Praat starts up and that's also why this environment is called the shell, because it provides the framework for the entire Praat functionality.
How do you know whether a script runs in the Praat shell? Well, that's easy: If you create a new script with the
Now, what about
Zoom in is one of many editor commands, i.e. a command which is only available in the GUI when a sound editor (or any other editor) is open. As we noticed above, editor commands can't be readily used in scripts which reside in the shell environment. Can they be used at all? Yes, of course, they feel perfectly at ease in scripts which reside in the editor's environment. Scripts which run in an editor's environment are created or opened with
Let's try it and create our first editor script. We'll use the tone which was created with
Select > Move cursor to...and type 0.19
- then choose
Select > Move end of selection by...and type 0.02
- finally, choose
View > Zoom to selection
This is what we want to achieve with the script, so let's paste the history:
Move cursor to: 0.19 Move end of selection by: 0.02 Zoom to selection
To test the script, choose
If you have a close look at the script editor containing the newly created editor script you'll notice a small but important difference to a script editor containing a shell script (just open a new shell script to see the difference; yes, you can have multiple script editors open simultaneously). The difference is in the window title: shell scripts have only their name in the title (untitled script for unsaved/unnamed scripts) while editor scripts have their name plus the specification of their environment in square brackets. The specification resembles the specification of the object in the Praat Objects list: ID, object type, and object name. If the tone was the first object which was created after starting up Praat, the specification should look like
One shell environment,
many editor environments
This is a remarkably precise and strict specification of the environment and Praat is in fact very serious about it: This script wouldn't run with another editor! Every open editor initiates its own environment and every editor script is dedicated to exactly one and only one editor environment. That means, if you create a new tone and open it in an editor, the existing script won't do anything to that editor. The new editor is specified as, for example,
To use an existing editor script with a new editor there are two options:
- Create a new empty editor script in the new editor, then copy the statements from the existing script to the new script and run it.
- Save the existing script to your harddrive, open it in the new editor environment (
File > Open editor script...), and run it.
Permanent shell environment,
transient editor environments
Editor environments are transient, i.e. they only exist as long as the respective editor window is open. When you close an editor window its environment ceases. If you create an editor script and then close the editor to which it belongs, the script is homeless. If you try to run a homeless editor script Praat will crash, so be careful! If you accidentally closed an editor window and made a script homeless you can make the script happy again by reopening the object, hence restoring the script's familiar environment.
To summarize: There is one permanently available shell environment and as many temporarily available editor environments as there are open editor windows. Each editor environment is autonomous and strictly specified. Each editor script belongs to exactly one editor environment, which is specified in the window title of the script editor.
The Praat command history, by the way, is global and indifferent regarding environments, i.e. it obstinately records every single GUI action without interest in its environmental origin.