| 1 | <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 | <title>FAQ: Scripts</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 | FAQ: Scripts |
| 13 | </b></font></table></table> |
| 14 | <p><b>Question</b>: how do I do something to all the files in a directory?</p> |
| 15 | <p>Answer: look at <a href="_fileNames-S-H_.html"><b><code><font size=+1>fileNames$#</font></code></b></a> () or <a href="Create_Strings_as_file_list___.html">Create Strings as file list...</a>.</p> |
| 16 | <dl> |
| 17 | <dd style="position:relative;padding-left:1em;text-indent:-2em"> </dd> |
| 18 | </dl> |
| 19 | <p><b>Question</b>: why doesn't the editor window react to my commands?</p> |
| 20 | <p>Your commands are probably something like:</p> |
| 21 | <code> Read from file: “hello.wav”<br></code> |
| 22 | <code> View & Edit<br></code> |
| 23 | <code> Zoom: 0.3, 0.5<br></code> |
| 24 | <p>Answer: Praat doesn’t know it has to send the <b>Zoom</b> command to the editor window called <b>14. Sound hello</b>. There could be several Sound editor windows on your screen. According to <a href="Scripting_7_1__Scripting_an_editor_from_a_shell_script.html">Scripting 7.1. Scripting an editor from a shell script</a>, you will have to say this explicitly:</p> |
| 25 | <code> Read from file: “hello.wav”<br></code> |
| 26 | <code> View & Edit<br></code> |
| 27 | <code> editor: “Sound hello”<br></code> |
| 28 | <code> Zoom: 0.3, 0.5<br></code> |
| 29 | <dl> |
| 30 | <dd style="position:relative;padding-left:1em;text-indent:-2em"> </dd> |
| 31 | </dl> |
| 32 | <p><b>Problem</b>: a line like “<i><code><font size=+1>Number = 1</font></code></i>” does not work.</p> |
| 33 | <p>Solution: names of variables should start with a lower-case letter.</p> |
| 34 | <dl> |
| 35 | <dd style="position:relative;padding-left:1em;text-indent:-2em"> </dd> |
| 36 | </dl> |
| 37 | <p><b>Question</b>: why do names of variables have to start with a lower-case letter? I would like to do things like “<code><font size=+1>F0 = Get mean pitch</font></code>”.</p> |
| 38 | <p>Answer: Praat scripts combine button commands with things that only occur in scripts. Button commands always start with a capital letter, e.g. <code><font size=+1>Play</font></code> (there is a button <b>Play</b>). Script commands always start with lower case, e.g. <code><font size=+1>writeInfoLine: “Hello”</font></code> (<code><font size=+1>writeInfoLine</font></code> is a built-in function). A minimal pair is “<code><font size=+1>select</font></code>”, which simulates a mouse click in the object list, versus “<code><font size=+1>Select...</font></code>”, which sets the selection in editor windows. If we allowed initial capitals, variable names would become rather ambiguous in assignments, as in “<code><font size=+1>x = Get</font></code>”, where “<i><code><font size=+1>Get</font></code></i>” would be a variable, versus “<code><font size=+1>x = Get mean</font></code>”, where <b>Get mean</b> is a button command. To prevent this confusion, Praat enforces a rigorous lower-case/upper-case distinction.</p> |
| 39 | <dl> |
| 40 | <dd style="position:relative;padding-left:1em;text-indent:-2em"> </dd> |
| 41 | </dl> |
| 42 | <p><b>Question</b>: how do I convert a number into a string?</p> |
| 43 | <p>Answer: <code><font size=+1>a$ = string$ (a)</font></code></p> |
| 44 | <p><b>Question</b>: how do I convert a string into a number?</p> |
| 45 | <p>Answer: <code><font size=+1>a = number (a$)</font></code></p> |
| 46 | <h3>Links to this page</h3> |
| 47 | <ul> |
| 48 | <li><a href="FAQ__Frequently_Asked_Questions_.html">FAQ (Frequently Asked Questions)</a> |
| 49 | </ul> |
| 50 | <hr> |
| 51 | <address> |
| 52 | <p>© Paul Boersma 2001,2004,2011,2013,2014,2023</p> |
| 53 | </address> |
| 54 | </body> |
| 55 | </html> |