Repeat script - Once per file

I have a script in a button, that I want to run once per file. So it should do each file individually: after script runs on one file, it should automatically move on to the next and repeat the script on the next file. They can't all be done together as the script is applying unique information for each file.

At the moment I use SELECT NEXT which goes to the next file and I click the button again to run on the next file. But can I tell the script to start over once on the next file?

You don't need to use Select Next or do anything special for this.

If you have an Opus button that runs something like:

MyScript.vbs {filepath$}

Opus will automatically run the script for each selected file, one after the other.

If you want it to be run on all items in the directory, without having to select them first, add an appropriate select command before the script. (e.g. Select ALL or Select ALLFILES DESELECTNOMATCH if you only want files.)

Thanks leo.

Can I get it to repeat on each file with the script inside the button as well?

I'm actually combining it with Opus' command "SetAttr DESCRIPTION" to add the description to a folder. The script reads from a file inside the folder and copies the info to the clipboard, and I used Opus to add the clip to the description.

So I have these Opus commands, followed by the script:

[quote]@runmode hide
@nodeselect
Rename REGEXP PATTERN="(.*)" TO="\1"
sync:dopusrt /cmd SetAttr DESCRIPTION "{clip}" {allfilepath}
sync:dopusrt /cmd SELECT NEXT {allfilepath}
[/quote]

You've made things way more complicated than they need to be. :slight_smile:

Actually, what is that Rename even doing? :slight_smile: It's renaming the files to the same names they already have. The stuff below the rename is not a rename script, if that's what you were thinking; those are just additional commands which get run after the rename, and the rename is doing nothing at all there, so you can get rid of it. (Rename scripts are quite different, start with @script, and would be VBScript or similar rather than further Opus commands.)

If you just want to set the selected files' descriptions to what's in the clipboard, all you need is this:

SetAttr DESCRIPTION="{clip}"

(BTW, this command may still go wrong if the clipboard contains quotes. In the unlikely event that it contains quotes and what comes after them looks like further arguments to the SetAttr command, it could do some weird things, too.)

I just meshed things around until it worked. lol

The Rename part, was there just so I could include the vbscript inside the button, and not in a preset or other file.

I have tried this:

[quote]SetAttr DESCRIPTION "{clip}"
@script vbscript
v:script.vbs[/quote]

It keeps giving me the same description for each selected file. I believe it starts off going through all the files individually and adding each files info to the clipboard. And then opus uses (or maybe it ends up with) the last files information that was copied to the clipboard and adds to the description of all files.

But what I need is for it to do is: go to file 1 & copy it's information from that file to the clipboard and then add to the description with opus. Then go to file 2 and do the same thing. And repeat for every file.

That's why I tried to use Select Next, and was hoping I could get opus to loop the script again once on the next file.

I don't know if I've explained this well...

@script only works with Rename and with the v:script.vbs stuff I've got no idea what you're trying to do there, to be honest. :slight_smile:

If you want a button to call a script then just put the script in a standard .vbs file and call it like you would normally (like any other exe or batch file).

(You can put the script into the button by "abusing rename scripting", which I've written a guide to, but ignore that until you have the basics working. It adds a lot of complexity to things and should only be used once you understand what you're doing.)

You probably want to make a script which you pass the filenames to (or one filename at a time, running it multiple times), which then works out what description to set and then calls the Opus SetAttr command to set it.

i.e. Make the script call SetAttr; don't try to make SetAttr call a script (which is impossible). (And there's no need to trash your clipboard just to pass info from a script to a command; there are better ways to do that. :slight_smile:)

Scripts can call Opus commands via dopusrt.exe; there are a bunch of examples where scripts do that in the Buttons forum; if you have trouble finding one shout and I'll have a look for a good example.

Ah oky, thankyou! Guess I didn't know what I was doing either. I will have to try redo it differently as you explained. I didn't really understand that opus and vb could be written together like that. I'll look into and see what I can do. Thanks for the help.