Debian Codegraph @

docs/manual/ScriptEditor.html

raw
1 <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2 <title>ScriptEditor</title>
3 <style>
4 td { padding-left: 5pt; padding-right: 5pt; }
5 th { padding-left: 5pt; padding-right: 5pt; }
6 code { white-space: pre-wrap; }
7 dd { white-space: pre-wrap; }
8 </style>
9 </head><body bgcolor="#FFFFFF">
10
11 <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b>
12 ScriptEditor
13 </b></font></table></table>
14 <p>An aid to <a href="Scripting.html">scripting</a>.</p>
15 <p>The ScriptEditor is a text editor that allows you to edit, save, and run any <a href="Praat_script.html">Praat script</a>. You can type such a script from scratch, but it is sometimes easier to use the <a href="History_mechanism.html">History mechanism</a>, which automatically records all your commands and mouse clicks, and which can paste these directly into a ScriptEditor.</p>
16 <p>To add a script as a button to a fixed or dynamic menu, use <a href="Add_to_fixed_menu___.html">Add to fixed menu...</a> or <a href="Add_to_dynamic_menu___.html">Add to dynamic menu...</a> from the <a href="File_menu.html">File menu</a>.</p>
17 <h2>Example 1</h2>
18 <p>In this example, we create a fixed button that will play a 0.4-second sine wave with a specified frequency.</p>
19 <p>First, we create a ScriptEditor by choosing <a href="New_Praat_script.html">New Praat script</a> from the <a href="Praat_menu.html">Praat menu</a>. Then, we choose <a href="Clear_history.html">Clear history</a> from the <b>Edit</b> menu in the ScriptEditor. We then perform some actions that will create a sine wave, play it, and remove it:</p>
20 <dl>
21 <dd style="position:relative;padding-left:1em;text-indent:-2em">1. Choose <b>Create Sound as pure tone...</b> from the <a href="New_menu.html">New menu</a> and click OK.</dd>
22 <dd style="position:relative;padding-left:1em;text-indent:-2em">2. Click <b>Play</b> in the dynamic menu.</dd>
23 <dd style="position:relative;padding-left:1em;text-indent:-2em">3. Click the fixed <b>Remove</b> button.</dd>
24 </dl>
25 <p>We then choose <a href="Paste_history.html">Paste history</a> from the <b>Edit</b> menu in the ScriptEditor (or type <a href="Keyboard_shortcuts.html">Command-H</a>). The text will now contain at least the following lines (delete any other lines):</p>
26 <code> Create Sound as pure tone: "tone", 1, 0, 0.4, 44100, 440, 0.2, 0.01, 0.01<br></code>
27 <code> Play<br></code>
28 <code> Remove<br></code>
29 <p>We can run this script again by choosing <b>Run</b> from the <b>Run</b> menu (or typing <a href="Keyboard_shortcuts.html">Command-R</a>). However, this always plays a sine with a frequency of 440 Hz, so we will add the variable "Frequency" to the script, which then looks like:</p>
30 <code> #form Play a sine wave<br></code>
31 <code> #positive Frequency<br></code>
32 <code> #endform<br></code>
33 <code> Create Sound as pure tone: "tone", 1, 0, 0.4, 44100, frequency, 0.2, 0.01, 0.01<br></code>
34 <code> Play<br></code>
35 <code> Remove<br></code>
36 <p>When we choose <b>Run</b>, the ScriptEditor will ask us to supply a value for the "Frequency" variable. We can now play 1-second sine waves with any frequency.</p>
37 <p>It is advisable to supply a standard value for each argument in your script. If the duration should be variable, too, the final script could look like:</p>
38 <code> #form Play a sine wave<br></code>
39 <code> #positive Frequency 440<br></code>
40 <code> #positive Duration 1.0<br></code>
41 <code> #endform<br></code>
42 <code> Create Sound as pure tone: "tone", 1, 0, duration, 44100, frequency, 0.2, 0.01, 0.01<br></code>
43 <code> Play<br></code>
44 <code> Remove<br></code>
45 <p>When you run this script, the ScriptEditor will ask you to supply values for the two variables, but the values "440" and "1.0" are already visible in the form window, so that you will get a sensible result if you just click <b>OK</b>.</p>
46 <p>If this script is useful to you, you may want to put a button for it in the <a href="New_menu.html">New menu</a>, in the <b>Sound</b> submenu:</p>
47 <dl>
48 <dd style="position:relative;padding-left:1em;text-indent:-2em">1. Save the script to a file, with <b>Save</b> from the <b>File</b> menu. The file name that you supply, will be shown in the title bar of the ScriptEditor window.</dd>
49 <dd style="position:relative;padding-left:1em;text-indent:-2em">2. Choose <a href="Add_to_fixed_menu___.html">Add to fixed menu...</a> from the <b>File</b> menu. Supply <b>Objects</b> for the <i>window</i>, <b>New</b> for the <i>menu</i>, "Play sine wave..." for the <i>command</i>, <b>Create Sound from formula...</b> for <i>after command</i>, and "1" for the depth (because it is supposed to be in a submenu); the <i>script</i> argument has already been set to the file name that you supplied in step 1.</dd>
50 <dd style="position:relative;padding-left:1em;text-indent:-2em">3. Click <b>OK</b> and ensure that the button has been added in the <a href="New_menu.html">New menu</a>. This button will still be there after you leave the program and enter it again; to remove it from the menu, use the <a href="ButtonEditor.html">ButtonEditor</a>.</dd>
51 </dl>
52 <h2>Example 2</h2>
53 <p>In this example, we will create a shortcut for the usual complex pitch-analysis command.</p>
54 <p>First, we perform the required actions:</p>
55 <dl>
56 <dd style="position:relative;padding-left:1em;text-indent:-2em">1. Select a Sound object.</dd>
57 <dd style="position:relative;padding-left:1em;text-indent:-2em">2. Click <b>To Pitch...</b> and set the arguments to your personal standard values.</dd>
58 <dd style="position:relative;padding-left:1em;text-indent:-2em">3. Click <b>OK</b>. A new <b>Pitch</b> object will appear.</dd>
59 </dl>
60 <p>We then paste the history into the ScriptEditor, after which this will contain at least a line like (delete all the other lines):</p>
61 <code> To Pitch: 0.01, 150, 900<br></code>
62 <p>You can run this script only after selecting one or more Sound objects.</p>
63 <p>If this script is useful to you, you may want to put a button for it in the dynamic menu:</p>
64 <dl>
65 <dd style="position:relative;padding-left:1em;text-indent:-2em">1. Save the script to a file, with <b>Save</b> from the <b>File</b> menu.</dd>
66 <dd style="position:relative;padding-left:1em;text-indent:-2em">2. Choose <a href="Add_to_dynamic_menu___.html">Add to dynamic menu...</a> from the <b>File</b> menu. Supply "Sound" for <i>class1</i> (because the button is supposed to be available only if a Sound is selected), "0" for <i>number1</i> (because the command is supposed to work for any number of selected Sound objects), "To Pitch (child)" for the <i>command</i>, "To Spectrum" for <i>after command</i>, and "0" for the depth (because it is not supposed to be in a submenu); the <i>script</i> argument has already been set to the file name that you supplied in step 1.</dd>
67 <dd style="position:relative;padding-left:1em;text-indent:-2em">3. Click <b>OK</b> and ensure that the button is clickable if you select one or more Sound objects. This button will still be available after you leave the program and enter it again; to remove it from the dynamic menus, use the <a href="ButtonEditor.html">ButtonEditor</a>.</dd>
68 </dl>
69 <h3>Links to this page</h3>
70 <ul>
71 <li><a href="Add_action_command___.html">Add action command...</a>
72 <li><a href="Add_menu_command___.html">Add menu command...</a>
73 <li><a href="Add_to_menu___.html">Add to menu...</a>
74 <li><a href="buttons_file.html">buttons file</a>
75 <li><a href="hidden_commands.html">hidden commands</a>
76 <li><a href="Objects_window.html">Objects window</a>
77 <li><a href="Open_Praat_script___.html">Open Praat script...</a>
78 <li><a href="plug-ins.html">plug-ins</a>
79 <li><a href="Scripting_1__Your_first_scripts.html">Scripting 1. Your first scripts</a>
80 <li><a href="Scripting_2__How_to_script_settings_windows.html">Scripting 2. How to script settings windows</a>
81 <li><a href="Scripting_7_2__Scripting_an_editor_from_within.html">Scripting 7.2. Scripting an editor from within</a>
82 <li><a href="What_was_new_in_3_5_.html">What was new in 3.5?</a>
83 <li><a href="What_was_new_in_3_6_.html">What was new in 3.6?</a>
84 <li><a href="What_s_new_.html">What's new?</a>
85 </ul>
86 <hr>
87 <address>
88 <p>© ppgb 20140107</p>
89 </address>
90 </body>
91 </html>