Scripting 6.8. Messages to the user

If the user makes a mistake (e.g. types conflicting settings into your form window), you can use the exit directive (\SS5.8) to stop the execution of the script with an error message:

form My analysis
    real Starting_time_(s) 0.0
    real Finishing_time_(s) 1.0
endform
if finishing_time <= starting_time
    exit The finishing time should exceed 'starting_time' seconds.
endif
# Proceed with the analysis...

For things that should not normally go wrong, you can use the assert directive:

power = do ("Get power")
assert power > 0

This is the same as:

if (power > 0) = undefined
    exit Assertion failed in line xx (undefined): power > 0
elsif not (power > 0)
    exit Assertion failed in line xx (false): power > 0
endif

You can prevent Praat from issuing warning messages:

nowarn do ("Save as WAV file...", "hello.wav")

This prevents warning messages about clipped samples, for instance.

You can also prevent Praat from showing a progress window:

noprogress do ("To Pitch...", 0, 75, 500)

This prevents the progress window from popping up during lengthy operations. Use this only if you want to prevent the user from stopping the execution of the script.

Finally, you can make Praat ignore error messages:

nocheck do ("Remove")

This would cause the script to continue even if there is nothing to remove.

Links to this page


© ppgb, April 7, 2013