Command

The Command object is used by a script to run Opus commands. Any command that you can run from a button or hotkey you can run from a script - a script can even run commands added by other scripts. Fundamentally, using the Command object is similar to configuring an Opus button. You add one or more command lines to the object just the same as you add one or more command lines to a button's function. You can tell it which files and folders to act upon, and you can use the various methods and properties of the object to modify the behavior of the command. Once the object has been initialized you can use the Run or RunCommand methods to invoke the command.

A Command object can be created by the DOpusFactory.Command method. By default, this object has no source, destination, files to operate on, etc. - you must use the appropriate methods to configure the command before running it. You can also retrieve a Command object from the Func.command property, and in this case the source, destination, files to operate on and several other properties are pre-initialized for you.

Property Name
Return Type
Description

deselect

bool

dest

desttab

filecount

int

Returns the number of items in the files object.

files

linecount

int

Returns the number of instruction lines added to the command.

progress

results

After every command that is run with this object, a Results object is available from this property. This provides information about the outcome of the command.

source

sourcetab

vars

Method Name

Arguments

Return Type

Description

AddFile

int

This method returns the total number of items in the collection.

AddFiles

int

Adds the items in the specified collection to the list of items this command is to act upon. The return value is the new number of items in the collection.

AddFilesFromClipboard

none

int

Adds the contents of the clipboard to the collection of items this command is to act upon. This method supports both files and file paths copied to the clipboard as text. The return value is the new number of items in the collection.

AddFilesFromFile

<string:path> <string:encoding>

int

The return value is the new number of items in the collection.

AddFilesFromFolder

<string:path>

int

AddLine

<string:instruction>

none

Adds the specified instruction line to the command that this object will run. The AddLine method lets you build up complicated multiple line commands - add each line in turn and then run the command using the Run method. For a single line command it is simpler to use the RunCommand method.

Clear

none

none

Clears all instruction lines from the command.

ClearFailed

none

none

ClearFiles

none

none

Clears the collection of items this command is to act upon.

ClearModifier

<string:modifier>

none

CommandList

none or <string:types>

i

internal (built-in) commands

s

script commands

u

user commands

Dlg

none

i

internal (built-in) commands

s

script commands

u

user commands

Dlg

GetModifiers

none

IsSet

<string:condition> [<string:command>]

bool

RemoveFile

int

Run

none

int

RunAsync

none

int

Asynchronously runs the command that has been built up with this object, without waiting for it to return. The return value indicates whether or not the command was launched successfully, but no further information about the results of the command is available.

RunCommand

<string:instruction>

int

Runs the single line command given by the instruction argument. Calling this method is the equivalent of adding the single line with the AddLine method and then calling the Run method.

RunCommandAsync

<string:instruction>

int

Asynchronously runs the single line command given by the instruction argument, without waiting for it to return. Calling this method is the equivalent of adding the single line with the AddLine method and then calling the RunAsync method.

SetDest

<string:path>

none

SetDestTab

none

Sets the command's destination to the specified tab. The destination path will be initialized from the tab automatically (so you don't need to call SetDest as well as SetDestTab).

SetFiles

none

You can also pass one of the other collection types, the same as with the AddFiles method.

SetModifier

<string:modifier> <string:value>

none

Using this method is the equivalent of using the AddLine method to add the modifier to the command as an instruction; e.g. Command.SetModifier("admin") is the same as Command.AddLine("@admin"). If the modifier requires a value it is passed as the second argument, e.g. Command.SetModifier("runmode", "hide").

SetProgress

none

Lets you share the progress indicator from one command with another command. You can pass this method the value of progress property obtained from another Command object.

SetQualifiers

<string:qualifiers>

none

This method lets you control which qualifier keys the command run by this object will consider to have been pressed when it was invoked. For example, several internal commands change their behavior when certain qualifier keys are held down - calling this method allows you to set which keys they will see.

The qualifiers argument must consist of one or more of the following strings (comma-separated): none, shift, ctrl, alt, lwin, rwin, win.

SetSource

<string:path>

none

SetSourceTab

none

Sets the command's source to the specified tab. The source path will be initialized from the tab automatically (so you don't need to call SetSource as well as SetSourceTab).

SetType

<string:type>

none

UpdateToggle

none

none

最后更新于