Protecting Against Inadvertant Renames

Hello,
I'm still getting my sea legs with scripting.

I have a script that renames files fine. The problem is that it will rename anything when I click the button. I'd like to put some protection in it so it will only rename JPG files.

Here's the script:

Rename {file} TO "Folder.jpg" @nodeselect

What can I do to prevent accidentally renaming say an MP3 file to folder.jpg?

If a jpg is not selected I want the script to do nothing. I have a lot of buttons and occasionally I click the wrong one.

Also, can you point me to a really thorough language reference? I see the commands and stuff in the help file but I want the language syntax. (IF Then; Case Logic; For/Next if that is available.)

Thanks.

If you change it to Rename *.jpg TO Folder.jpg it will only affect .jpg files, but if you have multiple jpegs selected it will try to rename them all to Folder.jpg.

There isn't any control flow in Opus scripting (except for the @keydown stuff) - it's not really "scripting" as such, more a flexible command system.

Got it. Works good.

Where can I look for information on conditional logic.

It appears that "IF" is a valid command.

If you want conditional logic (if-statements) then you'll need to use a VBScript rename preset (several examples in the Rename Scripting forum) or call an external script or batch file (or whatever).

What gives you that impression?

Well, that's good news.
Here on the Great Lakes, we're glad you're still with us. :laughing:

The original topic here was, "Protecting Against Inadvertant Renames."
I haven't used it until tonight, but you may find the function Modifier @confirm useful.
Info on this is available either in Directory Opus -> Help -> Help or from the online manual , under Command Control Codes.

[code]@confirm [[|[|]]] displays a confirmation dialog. If the negative choice in the dialog is chosen, the function is aborted at this point. You can configure the message and the button text displayed – if not specified, default strings are used. For example,

      @confirm Really copy files?
      @confirm Really proceed?|Of Course|No way [/code]

Just put @confirm Really proceed?|Of Course|No way as the first line of your button code !
Try it !

Regards,
David

You can found an example for IF...THEN...ELSE at This topic. I think you can use that idea for other statements too.

You need to be careful if you use DOS IF...THEN...ELSE in Opus buttons:

If it's a standard function then nothing much as those aren't recognised Opus commands and aren't (usually) recognised programs in the path, either. (i.e. there is no IF.exe, ELSE.exe, THEN.exe.)

If it's an MS-DOS function then it could cause all sorts of weird behaviour, unless you are careful not to use any Opus commands. If you mix Opus and non-Opus commands in an MS-DOS function then the function is split into several batch files which can cause the IF/THEN/ELSE logic to go haywire. Best to use an actual batch (or script) file in those cases.[/quote]

I would almost always recommend putting the commands in a separate .BAT or VBScript file and having the button pass arguments to that, if you don't want to use a VBScript rename preset/button for some reason.