<< Click to Display Table of Contents >> Navigation: Appendix > RoboTaskApp object |
There is no need to create the RoboTaskApp object when you are running or editing the script. It is created before you run the script and is available as a global object inside the script.
You can use it in external scripts by using the name RoboTask.App. For example:
For VB script
set obj = CreateObject("RoboTask.App")
For JS Script
var obj = new ActiveXObject("RoboTask.App");
RoboTaskApp.AddUserVariable(By Val Name as String, By Val Value as String)
Method.
Creates a user variable with the specified "Name" and assign the specified "Value" to it.
RoboTaskApp.Automation
Read-Write property, type - boolean
It is available for reading and writing. It contains the value of the RoboTask automation mode.
RoboTaskApp.Close
Method
Exits RoboTask.
RoboTaskApp.DelUserVariable(By Val Name as String)
Method.
Deletes the user variable with the specified "Name".
RoboTaskApp.DesktopAlert(ByVal Title as String, ByVal Msg as String, ByVal IconKind as Long, ByVal AlertKind as Long, ByVal Duration as Long, ByVal Width as Long, ByVal Height as Long, ByVal Corner as Long)
Method.
Shows desktop alert or balloon of tray icon with specified text
Title - [in] Title of the alert
Msg - [in] Message of the alert
IconKind - [in] The number of icon
0 - Information
1 - Warning (Exclamation)
2 - Error
3 - Default icon. When IconKind contains incorrect number the method shows default icon
AlertKind - [in] 0 - Alert window; 1 - Tray icon balloon.
Duration - [in] Duration in seconds
Width - [in] Width in pixels. If the value less that 330 the method uses default value (330). This parameter is being ignored if AlertKind=1
Height - [in] Width in pixels. If the value less that 76 the method uses default value (76). This parameter is being ignored if AlertKind=1
Corner - [in] The corner of alert window (This parameter is being ignored if AlertKind=1):
0 - top-left
1 - top-right
2 - bottom-left
3 - bottom right
RoboTaskApp.EventInfoEnabled(ByVal TaskNum as Long, ByVal EventNum as Long)
Read-only property. Value type - boolean.
Returns event status (enabled or disabled) by number of the task and event number.
TaskNum – [in] task number
EventNum – [in] event number
RoboTaskApp.EventInfoEventID(ByVal TaskNum as Long, ByVal EventNum as Long)
Read-only property. Value type - String.
Returns event identifier by number of the task and event number. For example: E_NET_LISTENER, E_WINDOW_WATCHER, E_GENERAL_CYCLIC, etc.
TaskNum – [in] task number
EventNum – [in] event number
RoboTaskApp.EventParameters(ByVal TaskNum as Long, ByVal EventNum as Long)
Read-only property, type - String.
Returns the event parameters as text. Each text line is an expression of the following type:
ParameterName = ParamaterValue
The set of parameters depends on the event type (EventID)
TaskNum – [in] task number
EventNum – [in] the event number in the task
RoboTask.EventsCount(ByVal TaskNum as Long)
Read-only property, type - Long
Returns the amount of events of the task.
TaskNum – [in] task number
RoboTaskApp.ExpandText(By Val Text as String)
Read-only property, type - String.
Expands a string containing RoboTask variables and returns the value of the string type.
For example: the string "File c:\autoexec.bat has length {FileSize(c:\autoexec.bat)} bytes" will be turned into the string "File c:\autoexec.bat has length 153 bytes"
RoboTaskApp.ExternalName(By Val ThreadID)
Read-only property, type - String.
Returns the "External Name" of a task by its ThreadID. You can specify an External Name on the "Advanced" tab of the task editor. You can find out the ThreadID of the current task using the RoboTaskApp.ThreadID property. A sample use is given below.
Sub Main
Dim extName As String
extName = RoboTaskApp.ExternalName(RoboTaskApp.ThreadID)
MsgBox("External name is "+ extName)
End Sub
RoboTaskApp.Minimize
Method.
Minimizes RoboTask into the tray icon.
RoboTaskApp.Restore
Method.
Restores the RoboTask window from the tray icon.
RoboTaskApp.ServiceMode
Read-only property. It contains a Boolean value: "True" if RoboTask is running as an NT service; "False" if RoboTask is running as a regular Windows application.
RoboTaskApp.SetThreadId(By Val ID as long)
Method
This is an auxiliary method that allows accessing local task variables from an external script that uses the RoboTask.App COM object (see the methods ExpandText, SetUserVariable, AddUserVariable, DelUserVariable). If you are using actions such as JS script, JS Evaluate, VB Script, VB Evaluate, you can use the built-in RoboTaskApp object, which is already properly formed. The use of this method is not required.
When using Python Script, JavaScript/Node.js script, use the RoboTask object. Examples are given here and here. The use of this method is not required.
However, the PowerShell script action does not contain a built-in object for accessing RoboTask functions. You must create an object inside the script and initialize it with the correct ThreadID. An example is given here.
For a PowerShell script, the current ThreadId of the task is passed through the ROBOTASK_SCRIPT_ID environment variable.
Example of the script:
$rt = New-object -ComObject RoboTask.App
#write-host $env:ROBOTASK_SCRIPT_ID
$rt.SetThreadId($env:ROBOTASK_SCRIPT_ID)
$rt.WriteToLog(0,"Hello",0)
If you want to run an external script using the Run Console Application or Run Program/Open Document actions, you can obtain the task's ThreadID using the {TaskThreadId} variable and pass this value as a parameter via environment variable, parameter, or file.
ID - Task thread ID
RoboTaskApp.SetUserVariable(By Val Name as String, By Val Value as String)
Method
Sets the value of the "Name" user variable to the specified "Value"
RoboTaskApp.StartTask(By Val ExternalName as String, By Val TaskParameters as String)
Method
Starts the task with the specified "External Name".
TaskParameters - you can pass some parameters into started task. May be an empty string. You need write down parameters like the text, each line should be like:
ParameterName=ParameterValue
•ParameterName – the name of parameter, any word consisting of letters and numbers;
•ParameterValue – value of parameter like any set of symbols.
RoboTaskApp.StepInfoActionID(ByVal TaskNum as long, ByVal StepNum as long)
Read-only property. Value type - string.
Returns the action identifier by task number and the step number.
Returned value is an action type identifier (for example: A_TASKS_START, A_TASK_WAITCOMPETE, A_GENERAL_RUN_PROG, etc.)
TaskNum – [in] task number
StepNum – [in] step number. Step number begins from 0.
RoboTaskApp.StepInfoName(ByVal TaskNum as long, ByVal StepNum as long)
Read-only property. Value type - string.
Returns step name by task number and the step number.
TaskNum – [in] task number
StepNum – [in] step number. Step number begins from 0.
RoboTaskApp.StepInfoEnabled(ByVal TaskNum as long, ByVal StepNum as long)
Read-only property. Value type - boolean.
Returns step status (enabled or disabled) by task number and the step number.
TaskNum – [in] task number
StepNum – [in] step number. Step number begins from 0.
RoboTaskApp.StepParameters(ByVal TaskNum as Long, ByVal StepNum as long)
Read-only property, type - String
Returns the step parameters as text. Each text line is an expression of the following type:
ParameterName = ParamaterValue
The set of parameters depends on the action type (ActionID)
TaskNum – task number
StepNum – step number. Step number begins from 0.
RoboTaskApp.StepsCount(ByVal TaskNum as long)
Read-only property, type - Long
Returns the number of steps in the task by the task number
TaskNum – task number
RoboTaskApp.StopTask(By Val ExternalName as String)
Method.
Stops the task with the specified "External Name".
RoboTaskApp.TaskCount
Method.
The read-only attribute of the numerical type. Returns the number of tasks registered in RoboTask.
RoboTaskApp.TaskEnabled(By Val ExternalName as String)
A Boolean attribute available for reading and writing. Allows you to read or set the "Enabled" parameter of the task with the specified "ExternalName".
For example:
RoboTaskApp.TaskEnabled("Check_email") = False
RoboTaskApp.TaskInfoExtname(ByVal NumTask as Long)
Read-only property, value type - string
Returns External name of the task by number of task (NumTask)
NumTask – [in] task number
Example of usage (Basic):
Sub Main
Dim cnt As Long
Dim nam As String
Dim extNam As String
Dim id As Long
Dim i As Long
cnt = RoboTaskApp.TaskCount
RoboTaskApp.WriteToLog(1,"Total "+Str(cnt)+" tasks",RoboTaskApp.ThreadID)
For i = 0 To cnt - 1
extNam = RoboTaskApp.TaskInfoExtName(i)
nam = RoboTaskApp.TaskInfoName(i)
id = RoboTaskApp.TaskInfoID(i)
RoboTaskApp.WriteToLog(3,extNam+"; "+nam+"; "+Str(id),RoboTaskApp.ThreadID)
Next
End Sub
RoboTaskApp.TaskInfoLastStart(ByVal NumTask as Long)
Read-only property, value type – DateTime
Returns the date and the time of the last running of a task. If the task has not been running from the moment of start of the RoboTask, the result will be zero.
NumTask – [in] task number
RoboTaskApp.TaskInfoName(ByVal NumTask as Long)
Read-only property, value type - string
Returns the name of the task by number of task (NumTask)
NumTask – [in] task number
RoboTaskApp.TaskInfoID(ByVal NumTask as Long)
Read-only property, value type - long integer
Returns folder ID of the task by number of task (NumTask)
NumTask – [in] task number
RoboTaskApp.TaskInfoFolderID(ByVal NumTask as Long)
Read-only property, value type - long integer
Returns ID of the task by number of task (NumTask)
TaskNum – [in] task number
RoboTaskApp.TaskInfoState(ByVal NumTask as Long)
Read-only property, value type - long integer
Returns status of the task by number of task (NumTask)
Possible returned values are:
0 - (tsManual) the task has no triggering events or its triggering events are disabled (see the RoboTaskApp.TaskEnabled property). It waits to be run manually or from another task.
1 - (tsIdle) the task has some enabled triggering events. It waits to be run automatically
2 - (tsDisabled) the task is disabled while it is being edited.
3 - (tsRunning) the task has been launched and it is running.
4 - (tsStopping) the task received the stop command, but it is yet running. After the task is completely stopped, its status becomes either tsManual or tsIdle.
TaskNum – [in] task number
RoboTaskApp.TaskNumByExternalName(ByVal ExternalName as String)
Read-only property, value type - Long
Returns the task number by ExternalName.
You can use the TaskInfo method to get ExternalName by the task number.
ExternalName – external task name. It is any string of characters. You can specify it while editing a task (see the "External Name" parameter on the "Advanced" tab of the task editor)
RoboTaskApp.ThreadID
Read-only property, type - Long
Returns the thread ID of the task. This value is required in the ExternalName property and WriteToLog method.
RoboTaskApp.Version
A read-only property of the string type. Contains the version number of RoboTask in it.
RoboTaskApp.WHandle
A read-only property of the Long type. Contains the Handle of the main RoboTask window. This value is necessary for some Windows API functions to work properly (for example, SendMessage, PostMessage).
RoboTaskApp.WriteToLog(By Val MsgType as Integer, By Val MessageStr as String, By Val ThreadID as Long)
Method
Records a message to the task log. To record a message to the system log of RoboTask, you should set the TreadID to 0.
MsgType – [in] message type: 0 – regular message, 1 – warning, 2 – error, 3 - user message;
MessageStr – [in] message string
ThreadID – [in] the Thread ID of the current task. It can be obtained using the RoboTaskApp.ThreadID property. If you set it to 0, the message will be recorded to the system log of RoboTask.
A sample use is given below.
Sub Main
Dim thr As Long
thr = RoboTaskApp.ThreadID
RoboTaskApp.WriteToLog(3, "Hello World", thr)
End Sub
Deprecated methods
These methods are not preferred, because they are not supported by scripting languages: Javascript and VB Script.
RoboTaskApp.EventInfo(ByVal TaskNum as Long, ByVal EventNum as Long, EventID as String, Enabled as Boolean)
Method. (deprecated method)
Allows you to get information about the triggering event by the task number and the step number in the task
TaskNum – [in] task number
EventNum – [in] event number
EventID – [out] event type identifier (for example: E_NET_LISTENER, E_WINDOW_WATCHER, E_GENERAL_CYCLIC, etc.)
Enabled – [out] event status (enabled or disabled)
RoboTaskApp.StepInfo(ByVal TaskNum as long, ByVal StepNum as long, ActionID as String, Enabled as Boolean, Name as String)
Method. (deprecated method)
Allows you to get information about the step using the task number and the step number in the task
TaskNum – [in] task number
StepNum – [in] step number
ActionID – [out] action type identifier (for example: A_TASKS_START, A_TASK_WAITCOMPETE, A_GENERAL_RUN_PROG, etc.)
Enabled – [out] step status (enabled or disabled)
Name – [out] action name
RoboTaskApp.TaskInfo(By Val NumTask as Long, ExtName as String, Name as String, ID as Long)
Method. (deprecated method)
Sets the properties of the task with the specified number ("NumTask").
NumTask - [in] task number
ExtName – [out] External Name;
Name – [out] task name;
ID – [out] internal numerical identifier.
This method is used to enumerate all tasks and extract the parameter of each task. A sample use is given below.
Sub Main
Dim cnt As Long
Dim nam As String
Dim extNam As String
Dim id As Long
Dim i As Long
cnt = RoboTaskApp.TaskCount
RoboTaskApp.WriteToLog(1,"Total "+Str(cnt)+" tasks",RoboTaskApp.ThreadID)
For i = 0 To cnt - 1
RoboTaskApp.TaskInfo(i,extNam,nam,id)
RoboTaskApp.WriteToLog(3,extNam+"; "+nam+"; "+Str(id),RoboTaskApp.ThreadID)
Next
RoboTaskApp.WriteToLog(3,"Total " + Str(cnt) + " tasks",RoboTaskApp.ThreadID)
End Sub
RoboTaskApp.TaskInfo2(ByVal NumTask as Long, FolderID as Long, State as TaskState)
Method (deprecated method)
An additional method for getting information about the task. It allows you to get the task folder identifier and the task status by the task number.
NumTask – [in] task number
FolderID – [out] the identifier of the folder with the task.
State – [out] the task status at the moment when the method is called. It can take one of the following values:
•tsManual – 0, the task has no triggering events or its triggering events are disabled (see the RoboTaskApp.TaskEnabled property). It waits to be run manually or from another task.
•tsIdle – 1, the task has some enabled triggering events. It waits to be run automatically
•tsDisabled – 2, the task is disabled while it is being edited.
•tsRunning – 3, the task has been launched and it is running.
•tsStopping – 4, the task received the stop command, but it is yet running. After the task is completely stopped, its status becomes either tsManual or tsIdle.
Related Topics