Closing the project from macro

Hello.
I’m trying to close the current project from macro script. Is it possible? There is no such command in the “insert command” list in macro dialog.
When i have added command “close” into macro script manually (in txt file), the Audacity crashed.
I’m trying to process a number of audacity aup3 projects. First I tried to use the option “files” in macro dialog - but it doesn’t work. It seems this way you can process only external files like mp3.
Now I’m trying in one long macro process several projects. I can open project, do processing, but can’t close it to open and process another one.
Maybe I’ wrong and there is more simple way.
I wiil be really glad for any suggestions.

I don’t think it can be done in a Macro, at least not without crashing, because the macro is running as the current project and cannot complete if the project is closed.
You can create a new project with a macro, but that macro can’t do anything in the new project because it’s a different project. When a macro runs, it is acting on the project in which it was opened.

I think the only way that you could do this is from an external programming language (such as Python). See: Scripting - Audacity Manual

I don’t think it can be done in a Macro, at least not without crashing, because the macro is running as the current project and cannot complete if the project is closed.

I just tested (on W10 with latest 3.0.1 alpha), and:

a) there is an Exit command available to Macros
b) It will exit and close Audacity
c) you will need to Save Project in the Macro first to a unique unused name - as otherwise you get the saving dialog
d) you’ll need to use the Save Project2 unless you carefully delete any pre-existing project that may be overwritten - as otherwise you’ll bet the overwrite warning dialog

Peter

That illustrates the problem clearly. The macro cannot continue after the “Exit:” command.

Which begs the question: why, them, do we have an Exit command available to Macros? :confused: :unamused:

Peter

So that you can tell Audacity to exit when the macro has completed (could be useful for macros that take a very long time to complete).
In other words, the “Exit” command can be useful as the final command in a macro.

The problem for Msv264 is that they want to run a macro on multiple projects, but the “context” for a macro is the project in which it is running.

Isn’t that what we have apply Macro to files for ?
https://manual.audacityteam.org/man/apply_macro.html#files

Peter

No. That’s for applying a macro to multiple audio files.
Msv264 wants to apply a macro to multiple Audacity projects, and as far as I’m aware, that can’t be done with a macro.

In fact, it’s really strange - you can do batch processing for an audio files, but can’t do the same for an Audacity projects.
My situation is really simple - I’ve got a lot of records, made in Audacity, and wish to process them with a set of effects - declick, decracle, debreath, equalizer, denoise, etc.
On the way I would like to make a backup copy.
It takes a lot of time, and it is completely not interesting to sit near computer and wait until it finishes one project to start processing the next one.
I think, the batch processing was invented especially for the situations like this.
Another strange question - why there is an Open project command in the macro command list? What for?

It’s probably not very useful for using in Macros, but the commands are not only for Macros. They are also for controlling Audacity from an external applications (see: Scripting - Audacity Manual) and from Audacity’s built-in scripting language “Nyquist” (see: Nyquist-Macros - Audacity Manual). The commands belong to an API (application programming interface) that can be used in multiple ways.

Macros can be seen as a very simple form of programming. An Audacity macro is just a list of commands that runs within the context of an Audacity project.

Python scripting is more flexible as it runs outside of Audacity and has control structures that allow looping, conditional statements, and everything else that comes with a full-featured programming language (it is also more complicated).



No. The batch process was invented especially for applying the same processes to multiple audio files.

Ok, thank you for an explanation.
I will try Python scripting.
But I think it would be helpful if somebody add to manual some words about Close command not suitable for macros.

Most people would probably not use the “Close” command because it isn’t in the Macro Editor. If I recall correctly there’s a few other commands that are excluded from the Macro Editor (because they are unsuitable for macros).

Which begs the question then: just how does one get a “Close” command in a Macro ? :confused:

Peter.

You would need to manually edit the macro’s .txt file.

I think the explanation Steve presented in this discussion is very useful for understanding how macros really work.
It will really help people if it would be added to manual.

So, which particular bit (or bits) that Steve wrote do you think would be useful in the Manual ?

Peter.

  1. I would suggest adding following text in general article about macros:
    The macro is running as the current project and cannot complete if the project is closed. So the “Close” command can’t be used in the macro.
    You can create a new project with a macro, but that macro can’t do anything in the new project because it’s a different project. When a macro runs, it is acting on the project in which it was opened.

  2. Also it would help if some text will be added to the description of the interface of the Macro Editor, where batch file processing is explained:
    Audacity allows to apply a macro to multiple audio files. Applying a macro to multiple Audacity projects can’t be done with a macro, if you wish to do it, you need to use Python scripting.

  3. It also won’t hurt to add some direct explanation to the description of “Close” command:
    “Close” command is excluded from the Macro Editor because it can’t be used in the macro.

Yes, but there is no “Close” command available in Macros - it’s only the clever uber-geek folk that play around with editing their Macros with a text editor and add in non-standard Macro commands. The Close was left out of the menu of commands available to Macro Manager on purpose.

You might argue that the macro Manager or the Macro Palette should reject any Macro that has an “illegal” command like “Close” in it. But that would be an enhancement request.

The Manual is written on the basis the we expect folk to use the Macro Manager as their way of building Macros.


I can think about adding something along these lines - I have to make some changes anyway to the Macros pages as a result of fixing a recent bug.


I’m not convinced that this is necessary - but I will give it some thought.

@Steve: are there any other commands that are deliberately excluded for Macros Manager ?

Peter.

Curiously I’ve just discovered that you can actually in 3.0.0 run Macros on 2.4.2 and earlier created older AUP files.

This is because in 3.3.0 only File>Open can be used to open the new AUP3 projects.

BUT with the old AUP project files from 2.4.2 and earlier for some strange reason (I’ve forgotten why) the developer who worked on Unitary Project enabled File>Import as well as File>Open to operate on AUP files - and thus Macros can work on AUP project files because they can Import them.

I can see that it might be useful for Macros to work on AUP3 projects as well as older AUP ones - so I’ll consider adding an ENH enhancement request for this.

Peter.

It may be worth noting on this page: https://alphamanual.audacityteam.org/man/Scripting_Reference
in the Intro section, that a few commands are intentionally omitted from the Macro manager (such as “Close:”) because they are unsuitable for use in macros.

(I’m not sure if we can update the manual at the moment or if we need to wait for Audacity 3.0.1 to be released).