How to get/use allfilepath according script selection change?

In my new script I want that folders are deselected and the files are then attached to a new mail. (Only as safeguarding, of course folders should not be selected for this function)
The deselection works, but the code {allfilepath|sep=,} is still passing all previously selected items.

I tried to use tab.Update();, but that does not change it.
To use FROMSCRIPT has also no influence.
What do I have to add/change? (Or can I not use allfilepath in this case?)

My code:

function OnClick(clickData) {
	var cmd = clickData.func.command;
	var tab = clickData.func.sourcetab;
	var Dlg = DOpus.Dlg;
	var fsu = DOpus.FSUtil;
	var lang = DOpus.language;
	cmd.deselect = false;

	DOpus.ClearOutput();

	if (clickData.func.qualifiers === "none") {
		cmd.RunCommand('Select tab.selected TYPE=files DESELECTOTHERTYPE');
		tab.Update();
		cmd.RunCommand('thunderbird -compose "attachment=\'{allfilepath|sep=,}\'"');
}
...
}

Additional info: With another qualifier all selected files and folders are archived to zip and attached to a mail.

The cmd object lets you add/remove/clear the list of files it will work on.

Also, tab.Update updates the snapshot of selected files in the tab object, but doesn't affect the cmd object.

ok. Thank you. This code snipped seems to work:

cmd.RunCommand('Select tab.selected TYPE=files DESELECTOTHERTYPE');
tab.Update();
cmd.ClearFiles();
cmd.AddFiles(tab.selected);
cmd.RunCommand('thunderbird -compose "attachment=\'{allfilepath|sep=,}\'"');
1 Like

Changing the visible selection in order to feed it back into commands is not always a good idea, as it means if you click on things while the script is running it will run on the wrong files. It also means the user's selection gets changed when they may not have wanted it to, and there's usually no need to do it as the script can do everything inside itself.

Generally, only change what's selected in the file display if changing the selection is the actual purpose of the button or script. If the aim is to change what the script runs on, there's usually a better way.

If you want the button to run on all files regardless of what's selected, just run cmd.ClearFiles() and then cmd.AddFiles(tab.files). No need to run the Select command at all, and tab.Update() probably isn't needed either (depending on what comes earlier in the script).

1 Like

Yes, if the user is a fast clicker perhaps this causes an issue.

The idea is to add only the selected files to the new mail. So the selection is important, but folders shall be ignored.

Ah, but your proposal leads to the solution with cmd.AddFiles(tab.selected_files):

cmd.ClearFiles();
cmd.AddFiles(tab.selected_files)

To keep it "in mind", but not necessary I think:
An alternative would be to use an enumerator like I did it in my first request regarding thunderbird mails. But I found a code from you which seems to be a little bit better then mine - I have to take a deeper look if it is relevant some day: {allfilepath} - Changing separetor between each file - #7 by Leo

1 Like