Tasker Script Reference

www.vista-software.com


Scripting Overview

Tasker includes a very basic scripting language in addition to its recording capability. Tasker is able to accomplish very advanced tasks with only a few commands: CLICK, GOTO, START, TYPE, and WAIT. Tasker is primarily a mouse and keyboard recorder which does not rely on a complex programming language, and script commands are meant to supplement your recordings. However, you may find that most tasks can be completed with script commands alone. You can write a script for anything that you can type on your keyboard, including any movement key (such as arrow keys) or any combination of keys (such as "Ctrl + V", "Alt + F", or "Shift + Ctrl + Left").

Tasker scripts have an advantage over other scripting programs because you can combine raw Windows messages (from your recording) with editable text script commands. Another advantage of Tasker scripts is that you don't have to learn hundreds of function calls or require the use of a large programming manual.

Why would you use scripts instead of just recording your actions? Sometimes it is easier to write a few lines of code rather than trying to get a perfect recording. In addition to that, a script file allows you to play back the commands back regardless of the computer's configuration (such as window placement), and even share the same script with other users. This capability makes scripts better than regular recordings for software testing teams. Finally, it is far easier to change a script file rather than re-record all of you actions for a lengthy process.

To see scripts in action, save a recording as a .TSX Tasker Editable Text File (see the "Save As Type" option in the File Save As prompt), or copy and paste one of the samples scripts below into Notepad and then run it in Tasker.

Remember that these script commands are in addition to all the commands that you can record (any action). We believe that the scripting commands are a nice compromise of power and simplicity. If you save in the standard ".TSK" binary format, nothing has changed from previous versions of Tasker. The ".TSK" format is binary and should not be modified. Please note that it is not recommended to alter a .TSK file to correct mistakes that were made while recording. You should just re-record the actions.

In the following reference section, you may copy and paste the colored code examples into Notepad and save them as a text file. They should work without modification on any PC running Windows 95 or higher.


Script Keywords

KeywordCLICK
PurposeClick the mouse at specified coordinates on the active window
Syntax &
Comments
CLICK [horizontal coordinate X] , [vertical coordinate Y]

* This command simulates a left mouse click based on the windows coordinates (0,0 is the upper left corner).
* NOTE: Use the GOTO command before using this command so that the correct window is activated.
* To click the mouse on the desktop, use the command "GOTO Program Manager" before using CLICK.
Example ; Launch the Paint application
; In Windows ME this next line might be something like "C:\Program Files\Accessories\mspaint.exe"
START mspaint.exe

; Give Paint a couple of seconds to start up
WAIT 2 seconds

; Switch to the Paint application
GOTO untitled - Paint

; Now, click the mouse in the drawing (it should leave a small pen mark)
CLICK 100, 100


KeywordGOTO
PurposeFind a running program (such as Notepad or Excel) and make it the active application
Also serves as a validation check during playback (like an IF statement), and can terminate a script if necessary
Syntax &
Comments
GOTO [window title text]

* The window text can be a partial match and GOTO will still work. For example, "GOTO sales" will find a window with the title of "Year Sales.txt - Notepad"
* No quotes or other delimiters are required. All text is interpreted literally.
* This command takes approximately 1/3 of a second to execute.
* If the window cannot be found, the playback will immediately terminate.
* NOTE: You should use GOTO regularly as a safety check in script files to be sure that your actions are occurring in the correct window.
Example ; Launch the Notepad application
START notepad.exe

; Give Notepad a second to start up
WAIT 1 second

; Switch to the Notepad application and put the cursor in its window
GOTO Untitled - Notepad


KeywordSTART
PurposeLaunch a program such as Notepad or Excel
Syntax &
Comments
START [executable name]

* In case the program cannot be started, include the entire directory path with the program name. You can get this path by right mouse clicking on the shortcut icon and viewing the Properties. For example, Microsoft Word may require a path such as "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" for Office XP.
* If the program cannot be started, the playback will immediately terminate.
* 16-bit MS-DOS programs cannot be run with this command directly, but can be properly handled with script commands. See below in the Example Code.
Example ; Launch the Notepad application
START notepad.exe
WAIT 1 second
GOTO Untitled - Notepad


KeywordTYPE
PurposeSend some text to be entered in the keyboard buffer
Syntax &
Comments
TYPE [single line of text]

* No quotes or other delimiters are required. All text is interpreted literally.
* The maximum size of the string that may be typed on a single line is 1,000 characters.
* NOTE: Use the GOTO command before using this command so that the correct window is activated.
* There is no delay between character output because the entire buffer is placed into the keyboard queue immediately.
* The following codes can be put in to generate dynamic input during playback:

{date} {time} {dtnumber} {random} {playbackloop}

Examples for all of these are given below.
Here are the codes for the special keyboard characters:

{altdown} {altup} {ctrldown} {ctrlup} {shiftdown} {shiftup}
{pagedown} {pageup} {up} {down} {left} {right}
{space} {enter/newline/return} {tab} {insert} {delete} {backspace}
{home} {end} {subtract} {decimal} {divide} {add}
{esc} {winkey} {appkey} {F1} - {F24}


* NOTE: Only one special character keyword can be used in each TYPE line. This means that "{altdown}" and "{altup}" must be on separate TYPE lines. The exceptions to this rule are {enter/newline/return}, {space}, and {tab} (because they are printable characters.
* If you put "{enter} / {newline} / {return}" in the script and the playback occurs in a popup dialog box, the system may use the Return character (the Enter Key) to press the default button. This can be used as a feature to close dialog boxes.
* See the samples scripts for proper usage of the special keyboard characters listed above.
Example ; Launch the Notepad application, wait for it to start, then switch to it
START notepad.exe
WAIT 1 second
GOTO Untitled - Notepad

; Press some keys
TYPE Here is text that is being typed by Tasker {newline}{newline}

; Here's dynamic text that is generated during playback:
TYPE Random={random} Date={date} Time={time} Date/Time As Number={dtnumber} Playback #={playbackloop}

; It will look like this after output:
; Random=6384 Date=01/06/2002 Time=01:34:10 Date/Time As Number=200201060134100606 Playback #=1

; Show the File menu (Alt+F) to demonstrate special characters:
TYPE {altdown}
TYPE f
TYPE {altup}


KeywordWAIT
PurposePause a certain amount of time before running the next command
Syntax &
Comments
WAIT [number of seconds]

* The word "seconds" is optional.
* This command is useful to give a large program enough time to load before switching to it. Sorry, but there is no other completely reliable way for Tasker to verify if a program has completed all of its initialization procedures.
* WAIT is affected by the Playback Speed option (previously, all WAIT delays ignored the Speed and played at the Normal setting)
* To WAIT less than one second (fractions of a second), you can use the Fast Factor (in Advanced Options) when combined with the Fast Speed playback. For example, to do a delay of half of a second, you can set the Fast Factor to 2x speed, and then play back at the Fast playback speed. 1 second will become 1/2 of a second. If the factor is set to 4x, 1 second becomes a quarter second.
* WAIT does not use the Windows "Sleep" command, but thread event timing methods, therefore background processing continues.
Example START notepad.exe
; Give Notepad a second to start up
WAIT 1 second
GOTO Untitled - Notepad


Keyword(Command Line Parameters)
PurposeControl execution of a Tasker Script File (.TSX) or Recording (.TSK)
Syntax &
Comments
/SPEED=[1, 2, 3, or 4]

/REPEATS=[any positive whole integer]

/CONTINUOUS=[1 or 0 (Boolean)]

* Please refer to the Tasker User's Guide for further information and usage examples.
* The command line parameters are not technically a part of Tasker Script, but they are the only method for programmatically controlling loops and playback speed.
* These parameters do not have any effect on compiled .EXE programs that were created by Tasker.
* The command line parameters do not alter any stored Tasker configurations - Tasker will start up with its previous settings.
Example The Tasker User's Guide has detailed step-by-step instructions on how to accomplish this, and includes sample screen shots.



Sample Scripts


The samples below demonstrate some of the possibilities when using Tasker script commands instead of recording your actions. These scripts can be cut and pasted into Notepad.

TypeSample.tsx

; TASKER SAMPLE SCRIPT
; PURPOSE: Demonstrates typing in a program

; Fire up Visual Notepad
start notepad.exe
wait 1 second
goto Untitled - Notepad

; Here's a single comment line
// This is another single comment line
/*
This is a multiple line comment
The end of the multi-line comment is on the next line
*/

; Here's a test of new lines (also called returns)
; Notice that you can use {return}, {newline}, {enter}, or even {\n}
type The quick brown fox{newline}jumped over{newline}
type the lazy dog.{enter}
type {return}
type {newline}
type Here's a test of lots of special characters:.,.<>/?;:'"[{]}\|`~!@#$%^&*()-_=+{newline}{newline}
wait 1 second

; Here's dynamic text that is generated during playback:
type Random={random} Date={date} Time={time} Date/Time As Number={dtnumber} Playback #={playbackloop}


MenuSample.tsx

; TASKER SAMPLE SCRIPT
; PURPOSE: Demonstrates menu navigation and {altdown}/{altup} capabilities

; Launch Notepad
START notepad.exe
WAIT 1
GOTO Untitled - Notepad
WAIT 1

; You can get to the System Menu of a window with "Alt + Space"
; Here's how you can maximize, minimize, close, etc. with the keyboard and system menu:
TYPE {altdown}
TYPE {space}
TYPE {altup}
WAIT 1
; The "X" is for Maximize (the underlined character in the menu)
TYPE x
WAIT 1

; Type some text and let the user read it
TYPE This is a Tasker menu test done on {date} at {time}...{return}
WAIT 1

; Before pressing some Alt+F keys, make sure that the ALT key
; is not toggled by pressing Escape a few times
TYPE {esc}
TYPE {esc}

; Now save this file by going through the "File - Save As" menu
; Go slow to watch it happen
TYPE {altdown}
TYPE F
TYPE {altup}
WAIT 1
TYPE A
WAIT 1

; Notepad also lets us choose "Save As" by doing: TYPE {ctrldown} TYPE s TYPE {ctrlup}

; Now the "Save As" dialog should be up, so type a unique filename and wait a second
TYPE C:\{dtnumber}.txt
WAIT 1

; We can now select the "Save" button with various methods:
;   1) Pressing the Enter key: "TYPE {enter}"
;   2) Tabbing over to it and pressing the space bar: "TYPE {tab}{tab}{space}"
;   3) Selecting its hotkey (underlined character):
;       TYPE {altdown}
;       TYPE s
;       TYPE {altup}

TYPE {enter}


KeyPressSample.tsx

; TASKER SAMPLE SCRIPT
; PURPOSE: Demonstrates key press combinations

; Launch Notepad
START notepad.exe
WAIT 1 second
GOTO Untitled - Notepad
WAIT 1 second

; Type some text so that we can move around in it
TYPE Here is some text{return}on multiple lines{return}for a demonstration
WAIT 1

; Highlight a whole word with Windows' "Ctrl + Shift + Left" combination
TYPE {ctrldown}
TYPE {shiftdown}
TYPE {left}
TYPE {shiftup}
TYPE {ctrlup}
WAIT 1

; Copy text to the clipboard with the "Ctrl+C" function
TYPE {ctrldown}
TYPE c
TYPE {ctrlup}
TYPE {end}
TYPE {return}
WAIT 1

; Paste the clipboard with the "Ctrl+V" function
TYPE {ctrldown}
TYPE v
TYPE {ctrlup}


MouseSample.tsx

; TASKER SAMPLE SCRIPT
; PURPOSE: Demonstrates usage of the mouse script commands

START notepad.exe
WAIT 1
GOTO Untitled - Notepad

; This should select the File menu if the title bar is normal size
; NOTE: These coordinate positions were determined from
; using the "Mouse Coordinates" tool in Tasker's Advanced Options

CLICK 15, 30
WAIT 1

; This should select the System menu if the title bar is normal size
CLICK 15, 10
WAIT 1

; Let's try the same commands with Microsoft Paint
; In Windows ME this next line might be something like "C:\Program Files\Accessories\mspaint.exe"
START mspaint.exe

; Give Paint a couple of seconds to start up, then switch to it
WAIT 2 seconds
GOTO untitled - Paint

; Click the "Flood Fill" tool button
; NOTE: This will only work if the tool palette is in
; the default position on the left side of the window!!
; If it is in a different position, you can use the Mouse Coordinates Tool to help you

CLICK 44, 78
WAIT 1

; Now, fill up the painting with whatever color is selected (probably black)
CLICK 100, 100