Any advanced examples of the "User Commands" out there?

I know that user commands have great potential and I think their functionality is deeper than I'm aware of.

Can the experts post their cool examples of how they use this option?

Also can multiple lines be stuffed into one command? like

"c:\acdsee\acdsee.exe" &name&

into a command called "MyViewer"

I think Ken is about the only person to do anything complex with User Commands (i.e. create ones which take a command-line). I only have two of them myself and they are both quite simple, just created so that I can call the same thing from two different places without duplicating the internals.

User Commands can have multiple lines.

I asked full a simple implementation of the host based scripting engine (just like the one used in the Rename function) but apparently it's far too much work to implement in a multi-threaded application like dopus for the few percentage people like me that would want to use it. Microsoft's Host based Scripting functionality is very powerful and easy to implement (I know because I've done it) but things start to get awfully complicated when you are running multiple threads. I fully understand this but being able to retrieve status info from Opus and applying your own logic and send back commands (even by simple RAW commands) would be quite useful.

The current user commands are useful but their extendability is reduced by the inability to perform complicated procedural control that a scripting language gives you.

I'm currently using a User Script that I called "GoExt", as follows:


It basically lets me add a "Go" button and provide key modifiers to open the path in different ways. Pretty simple there.

You can call VBScript from Opus buttons and then call Opus functions from the VBScript (via dopusrt.exe). The only issue is if you need functions to act on the current lister and the script might run for a while (since if you click on some other lister the script will then start acting on it).

WinRAR.exe u -ibck -m5 -as -z"C:\Ancient\List\Include.txt" -x@"C:\Ancient\List\Exclude.txt" &name& @"C:\Ancient\List\Include.txt"

It creates an SFX file backing up configs for ALL of my programs listed in the file "include.txt" and ignores the ones int the "exclude.txt"

This allows me to easily change the destination of the Sfx file by just calling

Backup "D:\Archive\Config.exe"

And I don't have to see or potentially corrupt that cryptic commandline.

User Commands are like custom toolbar buttons with one important difference—the command template. When you read the description of any Opus Raw Command, you will see each command has a its own template—the collection of various switches and options that govern what you can pass to the command, and how those options affect the command's behavior. When you make your own User command, you must create such a template. Otherwise, anything you can do in a User Command, you can also accomplish in a toolbar button.

The guidelines of how the options should work (not how you make them) is discussed in the Opus Help/Manual on the first page under the Opus Raw Commands section, where you see: /S, /O, /K, /A, and /M listed. You'll want to print that page out and have it handy. How the User Command template is actually constructed is discussed in the Opus Help/Manual under Predefined Commands - User-Predefined. That section could use a little more detail, but it has most of what you need. You'll want to print that page out and have it handy.

ADVICE: Do not be in a hurry to create a user command.

If what you want to accomplish has an ad-hoc, one-of, or unique nature then you will be better served by a custom toolbar button. When you find yourself making several toolbar buttons of very similar nature, with only a couple things varying between each, then it's time to start thinking about making a user command. If the various toolbar buttons aren't really related, then it makes less sense to make a user command out of them. Of course, there is some gray area here.

It's much easier to iron out all the wrinkles in a regular toolbar button. I recommend you start by reasoning out how to do each branch of your User Command as a separate toolbar button, which will help you ensure that each branch works without issue. Where you can, use Opus variables to pass the values to the various Internal and External commands in your toolbar buttons. While you do this, try to use the same descriptive variable names and a similar process flow across the various buttons. Then the logic will tend to emerge and help you see how the separate toolbar buttons might become one user command. Then you can go and design your user command by reconciling the various branch-buttons into one user command.

Q: Can multiple lines be stuffed into one command?

Yes, but with one important consideration, and you will see it touched upon from time-to-time in the forums here when users try to do a lot in one toolbar button—the race condition. I'm going to muddle through an explanation here, but Leo could provide better clarity than I can.

Opus is multi-threaded, for example when you list a folder, several processing threads will work to extract image thumbnails and display them in the current lister. When you start a Copy operation, I'm pretty sure it gets its own thread, which is what allows you to minimize the Copy Progress dialog and still keep right on working in the same file display doing something else. When you want to create a toolbar button or user command that does several different things in sequence, this concept is going to work against you. Consider this pseudo code:

A. Copy all images files from Location A to location B
B. Go to Location B
C. Select all the image files
D. Rename files to Image - 01.ext to Image - NN.ext
E. Reselect all image files (or never deselect them)
F. For each image file selected, resize it 256 x 256 in-place

(The Opus Image command can actually accomplish steps A and F above in a single command line. But set that knowledge aside because I need a simple multi-command example here.) If you tried to use multiple raw commands to accomplish the above, you might have issues. The lister display needs to be updated in Location B with all of the new file Meta Data before the Rename can work correctly on all the files; the more files, the longer Step A will take to complete and the longer the OS will take to update the meta data. The same is true after the Rename in Step D and before the resize in Step F. For some commands there is no reliable way for your toolbar button (or User Command) to be certain when such a processing step is complete. And each step in the above process is going to be reliant on the completion of the previous step. It depends a lot on what you are trying to do.

If you want to make something complex, you most likely will want/need logic branching. Opus toolbar buttons and user commands do not provided logic branching. The internal workings of each raw command definitely have logic branching, and you can pass those command parameters to interact with it. But the Opus Command Editor does not provide logic branching that governs the flow between different raw commands or external commands

The Advanced Command Editor now provides variables (new in Opus 9), but they must all be set upfront, and they cannot be changed later. (I'm still working myself on understanding the boundaries of what can be accomplished with Opus variables, but I do not think that you can @Set one variable based on the value of another variable.)

If it sound like I'm trying to discourage you, I'm not. But you need to be aware of the obstacles.

Personally, I use NT Command Scripts for my logic branching. Most of my User Commands work with external commands. And nearly all of them are MS-DOS Batch functions. I use Opus to pass things like the selected files, or the currently listed folder. I use the NT Command script (stored inside an Opus User Command) for my logic branching. When I want to have Opus perform a tack from within my NT Command Script, I use dopusrt.exe /CMD to call the Opus raw command.

NOTE: Keep in mind that this approach will actually increase the risk of a race condition occurring.

For the curious, you cannot (yet) take a previously existing and working NT Command script and simply paste into an Opus toolbar button or User Command and expect it to work straight away. But if you already have a working NT Command Script, it should now be possible to store it in Opus with minimal modification. Jon did a lot of work on the Advanced Command Editor for Opus 9 and its MS-DOS Batch Function processing is much better than that of Opus 8. There are still a few unresolved issues remaining, But so far nothing I don't know a workaround to.

Check out the PrintTree User Command I posted in Buttons & Toolbars. Download that and add it to your configuration. You can open up that User Command and see what I'm doing inside, as well as the toolbar buttons I included that use the command. If you have any questions on what I doing in that command or why, post them back here to this thread. PrintTree only takes two parameters. I have a couple more-complex User Commands under development, but I'm a ways from publishing them. So much Opus, so little time!

Also, something I have not played around with yet in Opus 9 is the @script modifier, which I believe allows you to store VBScript or JScript inside an Opus toolbar button or User Command. If you check out the Rename Scripting forum I believe they are using VBScript for complicated file rename operations.

That's a really good description there Ken and lots of food for thought.

What I'd like to see in DOpus is some event triggers, so I could, for example, run a command on certain events, like Lister Opening and Folder Pre and Post Open etc, although these would really only become useful when you can apply logical condition statements.

I have a few own user commands, as said by others, just to avoid duplicates in multiple places. They're mostly very simple.

One is this:

Line1: %gvdTool%\Shell\WinRar\winrar.exe a -ag-yyyymmdd-hhmmss -av -c- -cfg- -ep1 -hp -ibck -isnd -k -m5 -md4096 -os -r -ri1 -rr5p -s -sfx -t -tsm4 -tsc1 -tsa1 {dlgstring|Enter archive name (date && time will be added automatically)} {allfilepath$} Line2: @nodeselect

I added this to "all files and folders" filetype's context menu and a toolbar button. It makes a password-protected SFX of selected files for more securish archiving, by first asking a filename and then for the password. For an explanation of switches see Winrar's help.

Another one is this:

Line1: FileType NEW=.txt NEWNAME=Text-%COMPUTERNAME%-{date|yyyyMMdd}-{time|HHmmss}.txt
It creates a file with current timestamp and and the current PC's name. It's short but saves me some duplicates. I have a button, context-menu entry and a keyboard shortcut for this. Same for a "create folder" function.

A while ago I've experimented to mimic the synchronization tool with this:


It doesn't work as I wanted (does not delete folders, non-existing files, etc.) but might give you a clue.

A few days ago, I've asked about exitcodes of external programs and I've come to realize that it'd be better to use external batchfiles/progs than complex DOpus-commands, because the possibilities are somehow "limited".

Last but not least, I'd recommend that you prefix your user commands so that you can easily recognize your own commands in the dropdown box.