Copy files to all opened listers request

Can anyone write a script for me that make copy of selected files to all opened listers, not only destination? I'm talking about single listers, not dual mode.

PS. "Add to queue" function will be most welcome.

I change code of script that Leo writes to me for close all listers except source and destination. Seems to work, but maybe is a better way. I see separate copy process one after another instead of queue all copy functions in one window.

[code]function OnClick(clickData)
{
var funcListerId = clickData.func.sourcetab.lister + 0;
var cmd = clickData.func.command;
cmd.RunCommand("Clipboard COPY");
cmd.deselect = false;
cmd.ClearFiles();
for(var eListers = new Enumerator(DOpus.listers); !eListers.atEnd(); eListers.moveNext())
{
var lister = eListers.item();
if ((lister+0) == funcListerId)
continue;
cmd.SetSourceTab(lister.activetab);
if (lister.dual == 0)
{
if (!cmd.IsSet("STATE=Source"))
cmd.RunCommand("Clipboard PASTE COPYQUEUE");
}

}
}
[/code]

PS. And example in VB will be much better for me to understand how it works and starts making own scripts.

And one more - after I start copying, I want that this operation affect only on listers opened while I start copying, not those who I open after copying start (so, some kind of collecting destinations into a table before copy). I hope someone have few minutes to write something like that for me.

[code]Option Explicit
Dim lister
dim destix(1000)
dim sourx
dim ndest
dim xx
dim doCmd
dim cmd
ndest=0
dim t
For Each lister In DOpus.listers
if lister.state=1 then
sourx=lister.activetab.path
else
ndest=ndest+1
destix(ndest)=lister.activetab.path

  end if

Next

if ndest>0 then
for t=1 to ndest
if sourx<>destix(t) then
Set doCmd = DOpus.CreateCommand
'var doCmd = DOpus.NewCommand
cmd="Copy QUEUE {f} TO="&chr(34)&destix(t)&chr(34)
Dopus.Output " " & cmd
doCmd.RunCommand(cmd)
cmd="Select RESELECT"
doCmd.RunCommand(cmd)
end if
next
cmd="Select NONE"
doCmd.RunCommand(cmd)
end if
[/code]

This is my lame code. It works but not as I expect. Copy process is not queued but runs one after another. Also - reselecting everything is not nice method as I think. Can anyone help me? In VBscript?

If your first version worked other than you ended up with multiple queues, you probably just need to give the queue a name to force everything through the same queue. E.g. Clipboard PASTE COPYQUEUE "My Queue".

No, is not like that. Script copy files to one lister, then after process ends, copy the same files to another lister. I don't know how to run command without waiting for command ends.

PS. My second version works the same as first, except I understand more VBscript than Jscript. If someone help me with that first VBscript, then I think I understand a lot better how to do stuff like that.

Please indent your code properly, nobody can read and help if all lines are crimped to the left edge. o)
You might even be able to find errors yourself. o)

It's just few lines. I promise next time I indent my code if I learn how to use all this Opus stuff. For now I'm just starting. And I really can't made that script as I want, that's why at first I ask for help with write whole script. If it will be in VBscript then I'll understand a little more.

In Opus help is everything except some examples.

Maybe I better explain what I want to do.

  1. Read paths of all opened listers that are not source. Just active tab (if any of listers have more than one). And only single listers.
  2. Read list of selected files from source lister.
  3. Prepare one big queue copy operation - copy all selected files from source lister to every other lister.
  4. Start copying.

For now I made only first point. Rest I made wrong, I know that. And I have no idea how to made it good.

After start copying I want to even close all listers or open another one without affect or change operation.

In theory you can do cmd.SetModifier("async") to run the Copy command asynchronously but there actually seems to be a problem with that, which we'll fix in the next update.

And btw. - any chance that you can help me with that VB script just for show me the right way to do it? I suspect that I may do it much better.

Option Explicit
Dim lister
dim veve
dim destix(1000)
dim sourx
dim ndest
dim xx
dim doCmd
dim cmd
dim t
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

if ndest>0 then
  for t=1 to ndest
    if sourx<>destix(t) then
      Set doCmd = DOpus.CreateCommand
      doCmd.SetModifier("nodeselect")
      doCmd.SetModifier("async")
      cmd="Copy QUEUE=quiet {f} TO="&chr(34)&destix(t)&chr(34)
      veve=doCmd.RunCommand(cmd)
    end if
  next
  cmd="Select NONE"
  doCmd.RunCommand(cmd)
end if

This is latest version of my script. I'll be very happy if someone tells me what is wrong. Script works, I even add "async" (for future Opus version) but as I suppose it's written bad and can be done better way.

I think there should be some small script examples in Opus help. That may help people making their own scripts.

There are example scripts in the manual: Example Scripts.

For more examples, there's a whole area of this forum dedicated to scripts: Script Buttons & Add-Ins

I mean more like VBA where you have examples related to functions and methods. But thank you for your answer. I start with that samples.

What's not working as expected?
You are using @async and QUEUE together to only run those operations at the same time, which do not affect each other, is that your intention?

I see possible quirks with the copy command used in a fresh command object, which has no target/destination tab set.
It might be unclear what the copy operation uses as source, especially since you are using {f}, which is not recommended/supported officially in scripting scenarios (iirc). Maybe better use 'Copy QUEUE=quiet FILE="*" TO=""', so it does not start guessing what the source is.

Source is obvious - I start with source lister (single) using button, so source is just source, then script check which one is source (or dual) to skip this one.

Async so far do not work (but will be fixed, as leo said), so I'll see.

All I want that script works just for start copy operations. For now (as far as async doesn't work) runs as long as last copy operation starts. I though that maybe is some different method to made it better. I don't know.

PS. Using "{f}" is just for sending command to Opus - is part of internal Opus copy attributes. It's not part of script. Also - script checks number of listers open and if number of destinations is zero - do not start copying. And I don't use tabs for that, just single listers.