Scripting: How to select "Visible layers" via ExportSpriteSheet?

I’d like to use app.command.ExportSpriteSheet in my script.

Unfortunately, the documentation is somewhat unclear on some of its parameters, or perhaps it doesn’t accept all possible parameters.

layer apparently expects one layer name. If empty or otherwise not matching an existing layer, then the visible layers will be exported, but I need the selected layers.
I imagine the same is true of tag.

I realise I can sort of accomplish this by hiding non-selected layers and then showing them again, but that seems hacky.

Further questions about this:
What is bestFit? I don’t see anything by that name in the GUI. Is it something to do with the constraints for packing?
Is it possible to change the “Preview” option when using ui=true?
Is it possible to set the “Source”?
When using ui=true, is it possible to know whether the user did the export or Cancelled? It seems to return true either way.