Macros With Variables

From Audacity Wiki
Jump to: navigation, search
Anyone that has used Macros will be aware of how useful they can be, especially for repetitive tasks, but also aware that no user input is possible. The only way to run a "normal" Macro with different settings, is to modify the Macro. This limitation is overcome with Nyquist Macros.

This tutorial is written for Audacity 2.4.0 or later, and assumes some knowledge of Macros. If you are unfamiliar with Macros, it is recommended that you read the section about in the Audacity manual, and try out the feature before proceeding with this tutorial.

Some experience writing Nyquist scripts is also helpful, though links to necessary information will be provided throughout.

In this tutorial we will:

  1. Replicate the "Fade Ends" Macro (included in Audacity 2.4.0) as a Nyquist script.
  2. Convert the Nyquist script into an installable Nyquist plug-in.
  3. Add controls to set the length of the fades.
  4. Discus (briefly) the limitations and benefits of Nyquist Macros.
  5. What Next and References.

Fade Ends Macro

When viewed in the Macro Editor, we can see the scripting commands and the parameters for each command. The command names are the "human readable" names, and are written in the currently selected display language.

Num Command Parameters
01 Select Start="0" End="1"
02 Fade In Use_Preset="<Factory Defaults>"
03 Select Start="0" End="1" RelativeTo="ProjectEnd"
04 Fade Out Use_Preset="<Factory Defaults>"
05 Select Start="0" End="0"
06 -END-

We can also view the Macro file, which is a plain text file, saved in Audacity's Macro folder

Select:Start="0" End="1"
FadeIn:Use_Preset="<Factory Defaults>"
Select:Start="0" End="1" RelativeTo="ProjectEnd"
FadeOut:Use_Preset="<Factory Defaults>"
Select:Start="0" End="0"

Note that the command names in the Macro .txt file are the "machine readable" names. They are always a single word (no spaces), and generally written in CamelCase. These names are not translated, and use American English spelling. The command names end with a colon (":").

After each command name, the parameters (settings) for the command are given. Settings are in the form:


A value is one of:

  • int An integer (whole number). Examples: 1 2 3
  • double A fractional (decimal) number. Examples: 0.5 10.0 0.0
  • string Quoted text. Examples: "Hello World" "three + five" "add lorem ipsum"
  • enum A special keyword. Examples: JSON Waveform StartFreq
  • bool A true / false value. True is entered as the digit 1, false is the digit 0 (zero).
Macro commands are case sensitive
"ProjectEnd" is NOT the same as "proJectEnd"
Command names, Parameter names and enums must be written exactly as given in the Scripting Reference.

Understanding the Macro

This section provides a brief description of each of the commands used in this example.
For a full list of all parameters available for a command, refer to the Scripting Reference.


 Select: Start="0" End="1"
  • Select: Name of the command. Used to make or change the selection.
  • Start="0" The start time of the selection in seconds. The quotes around the value are optional.
  • End="1" The end time of the selection in seconds. The quotes around the value are optional.
  • By default, times are relative to the start of the project.

Warning icon Work in progress... (16th Feb 2020)