When you start AutoIt you will be asked to open a script file. A script file is a simple text file containing AutoIt keywords and functions that tell AutoIt what you want it to do. Script files are created in a simple text editor such as notepad.exe or a much better alternative.
Although AutoIt v3 scripts are just plain-text files they are usually given the file extension .au3 to help tell the difference between a script and a text file. If you used the full installer to install AutoIt you can execute an AutoIt script simply by double-clicking it. There are also various options to open, edit, or compile a script if you right-click on the .au3 file.
Here is an example script. Notice that ; is used for comments (much like REM in DOS batch files):
; This is my first script
MsgBox(0, "My First Script!", "Hello World!")
More complicated scripts may use functions, which are usually placed at the end of a script. Here is a similar script using functions:
; This is my second script (with functions)
MsgBox(0, "My second script!", "Hello from the main script!")
MsgBox(0, "My Second Script!", "Hello from the functions!")
The special array $CmdLine is initialized with the command line parameters
passed in to your AutoIt script. Note the scriptname is not classed as
a parameter; get this information with @ScriptName instead. A parameter
that contains spaces must be surrounded by "double quotes".
Compiled scripts accept command line parameters in
the same way.
$CmdLine is number of parameters
$CmdLine is param 1 (after the script name)
$CmdLine is param 2 etc
$CmdLine[$CmdLine] is one way to get the last parameter...
So if your script is run like this:
AutoIt3.exe myscript.au3 param1 "this is another param"
$CmdLine equals... 2
$CmdLine equals... param1
$CmdLine equals... this is another param
@ScriptName equals... myscript.au3
In addition to $CmdLine there is a variable called $CmdLineRaw that contains the entire command line unsplit, so for the above example:
$CmdLineRaw equals... myscript.au3 param1 "this is another param"
If the script was compiled it would have been run like this:
myscript.exe param1 "this is another param"
$CmdLineRaw equals... param1 "this is another param"
Note that $CmdLineRaw just return the parameters.
Note : only 63 parameters can be return by $CmdLine[...], but $CmdLineRaw will always returns the entire command line.
Form1: AutoIt3.exe [/ErrorStdOut] [/AutoIt3ExecuteScript] file [params ...]
Execute an AutoIt3 Script File
/ErrorStdOut Allows to redirect fatal error to StdOut which can be captured by an application as Scite editor. This switch can be used with a compiled script.
To execute a standard AutoIt Script File 'myscript.au3', use the command:
Form2: Compiled.exe [/ErrorStdOut] [params ...]
Execute an compiled AutoIt3 Script File produced with Aut2Exe.
Form3: Compiled.exe [/ErrorStdOut] [/AutoIt3ExecuteScript file] [params
Execute another script file from a compiled AutoIt3 Script File. Then you don't need to fileinstall another copy of AutoIT3.exe in your compiled file.
Form4: AutoIt3.exe [/ErrorStdOut] /AutoIt3ExecuteLine "command line"
Execute one line of code.
To execute a single line of code, use the command:
Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"')
The tray icon will not be displayed when using /AutoIt3ExecuteLine
NOTE: Correct usage of single- and double- quotation marks is important, even double single.