Scripted Output Destinations
You can use a script to set the output file as well. This script can be in any of the Merge events up to and including the "Start Next Print Driver" event.
You can access the current setting of the output string using the _printer.getOutputFile() call. If you are using multiple outputs you'll need to qualify that call with the printer name such as _printer.getOutputFile("PDF2").
To set a new output destination, use _printer.setOutputFile("newname") of the qualified equivalent _printer.setOutputFile("newname", "PDF2"). The new output name can have embedded $X variables, [fieldname] strings, and %x substitution as well, just as the basic command line -output can have. These substitutions happen just as the actual printing process begins.
If you are using the CombineDocuments option that combines all documents within a multi-document Merge run into a single output file, You can also use the _printer.setOutputFile() routine to change the output destination part way through that run.
See the _printer section for information on other printer-related scripting.