Nyquist can output to a file by opening a file stream, then “printing” to the file.
Typically this would be done by:
- Specifying the path with (set-dir “”)
- Open the file with (open :direction :output)
- Print to the specified file with (format [expr1 … ])
- Close the file stream with (close )
As an example on Windows, to create a text file called “test.txt” in the root directory (C:) containing the text “Hello World”
(setdir "C:/")
(setq file (open "test.txt" :direction :output))
(format file "Hello World")
(close file)
One important thing to notice is that the directory must be defined using forward slashes and not backslashes. This is because Nyquist uses backslash as an escape character.
Another thing to notice is that this does not work on Linux (or Mac ?) because they do not use the same drive letter notation.
(it probably does not work on Windows if the user has a limited account - can anyone confirm?)
On Linux, we could use “~/” to specify the users “Home” folder, so the Linux equivalent would be:
(setdir "~/")
(setq file (open "test.txt" :direction :output))
(format file "Hello World")
(close file)
If the default “working directory” was reliably in a usable location, then we could just use that and not worry about cross-platform differences.
In Audacity 1.3.12 and 1.3.13 (alpha) on Ubuntu, the default working directory is the users home folder. This is good.
To display the working directory - enter the following code in the Nyquist prompt:
(setdir ".")
What is the default working directory for Mac and Windows?