Copy files to all opened listers request

If it works so far, go with it, but I think the points I mentioned are still something to look at to bullet proof your solution.

For me it's not obvious that creating a new command object will use the lister as source in which you pressed the button. The command object offers a SetSource/Tab() method for that actually, so commands know for sure what to use as source. Consider to check the .source property of your newly created command object, it is unset. Why the copy command is still going to use the correct lister as source is a bit of coincidence or rather blurry DO magic, which might not always work out for you as expected.

Using "{f}" is just for sending command to Opus - is part of internal Opus copy attributes. It's not part of script.
"{f}" when used in conjunction with "cmd.RunCommand()" is scripting ground, Leo and Jon will correct me if I'm wrong, but it's use is not approved in this context. You should add the selected items by calling "cmd.AddFiles()" and get them from the "srcLister.activetab.selected" collection instead

And I don't use tabs for that, just single listers.
Rethink that. o)

Using {f} in a script is like using a command object without a defined source - it might work, but it might not :slight_smile:

Thank you for all advices, that "cmd.AddFiles()" etc. Would be really, really nice if someone write whole script to show me proper way this time, but if not - ok, I'll check later if I can do it myself. Even if I want to use "AddFiles", I don't know what to do next, but I'll find it. Maybe.

I didn't know that {f} is part of my script. I thought that is part of text variable which is used in "RunCommand" (and then it works like I really run command in Opus). Also, if is run always from active source lister, then will work proper. You say that I'm wrong and I must believe that, but still can't understand.

Ok, I give up. It's too complicated for me as far as I have no idea how it works. I know only basic stuff and Opus help is not so helpful for not experienced user like me. Maybe someone help me some day or maybe not. I'm happy that my method works anyway and if async start to work, I hope this resolve rest of potential problems.

If you are running the script via a hotkey or button/menu in the lister with the selected files, you are given a Command object that already has all the selected files added to it, and also already has the source folder tab set as its source (which is important not just for context like the command's current directory, but for which window the command's progress dialog appears over).

The OnClick method that a hotkey/button/menu script is run by has a clickData argument, and clickData.Func.Command is the Command object you should usually use, rather than creating a new one (which will have to guess about which folder tab it should attach itself to).

You can then run commands which work on the selected files by default, and they will use the files associated with the Command object (the selected files initially). If you want to change what those files are, you can call ClearFiles and similar methods, and AddFile (singular) with the full path to the file you want to add, or AddFiles (plural) with a container of multiple files (e.g. the pre-provided containers with a different tab object's selected items, or the container with all items in a tab if you want to ignore the selection and copy everything in the tab).

Commands like Copy (and most others) will work on the selection by default, unless overridden by specifying a particular file/path in their command line arguments.

Thank you for your help, but I'm not experienced programmer (or, in this case, not programmer at all - I have some experience but not that type) and without example I did not understand this I'm afraid.

[code]Option Explicit
Function OnClick(ByRef clickData)

Dim t, lister, veve, sourx, ndest, xx, doCmd, cmd, tab, selItem, folderEnum, folderItem
dim destix(1000)
ndest=0
For Each lister In DOpus.listers
if lister.dual=0 then
if lister.state=1 then
sourx=lister.activetab.path
else
ndest=ndest+1
destix(ndest)=lister.activetab.path
end if
end if
Next

DOpus.ClearOutput

Set cmd = clickData.func.command
cmd.deselect = false

If clickData.func.sourcetab.selected.count > 0 and ndest>0 Then
    cmd.Clear

	For Each selItem in clickData.func.sourcetab.selected
 		for t=1 to ndest
        	if sourx<>destix(t) then
            cmd.AddLine "copy QUEUE=quiet "&chr(34)&selItem.RealPath&chr(34)&" TO="&chr(34)&destix(t)&chr(34)
            end if
        next
	Next
    cmd.Run
End If

end function
[/code]

Hmm, I'm trying to not give up. :slight_smile:

Is this better?

And AT LAST everything works at once in one copying BUT every file is copy separate so I have no files count in copy dialog.

I was using this example when you first time start new script in button. I still don't know to made it like I want and/or by "AddFiles". I think I spend some time later but I do not suspect that it will be success. At least not without some examples of real code.

[code]Option Explicit
Function OnClick(ByRef clickData)

Dim t, lister, veve, sourx, ndest, xx, doCmd, cmd, tab, selItem, folderEnum, folderItem, lstsourc
dim destix(1000)
lstsourc=""
ndest=0

For Each lister In DOpus.listers
if lister.dual=0 then
if lister.state=1 then
sourx=lister.activetab.path
else
ndest=ndest+1
destix(ndest)=lister.activetab.path
end if
end if
Next

DOpus.ClearOutput

Set cmd = clickData.func.command
cmd.deselect = false

If clickData.func.sourcetab.selected.count > 0 and ndest>0 Then
cmd.Clear

For Each selItem in clickData.func.sourcetab.selected
	if lstsourc<>"" then lstsourc=lstsourc&" "
	lstsourc=lstsourc&chr(34)&selItem.RealPath&chr(34)
Next

For t=1 to ndest
	if sourx<>destix(t) then
		cmd.AddLine "copy QUEUE=quiet "&lstsourc&" TO="&chr(34)&destix(t)&chr(34)
	end if
Next

cmd.Run

End If

end function
[/code]

Finally it works almost like I want. Whole process starts at once, I can close all listers after operation starts. Almost perfect.

Except I see only total number of operations, not total number of files.

Ok, now async and queue works (after last update).