How do I get exact command syntax for a macro?

I have a collection of (speech) sound files with an erroneous sampling rate in the file, and see that there is a menu item in the track window for setting the sample rate. To avoid the drudgery of manually doing this for multiple files, I would like to create a macro that can be applied to the collection of files. To do that, I need to figure out the proper name of the command and parameter syntax for what I am manually mousing to. So either (a) what is the specific command plus parameter syntax for changing the sampling rate to 40000 or (b) even better, is there a macro recording facility in Audacity that translated pull-down menu selections into a list of commands and parameters that can be turned into a macro?

There is a command reference here: Scripting Reference - Audacity Manual

The command “SetProject” has an option to set the project rate.