Home |
Last modified: 07-12-2021 |
AutoIT is an alternative to applications like AutoHotKey to automate tasks through hotkeys/hotstrings and drive GUI applications. It used to be open-source — AutoHotKey was forked from AutoIT around 2005 —, but was closed-source later and is now freeware.
Its syntax looks like BASIC, while AHK is closer to C. AHK is updated frequently, while the latest release of AutoIt was in March 2018 with release 3.3.14.5.
In addition to native features, AutoIT is enhanced through User Defined Functions (UDFs).
Note that a plain "Hello, World!" with a MessageBox is about 1MB, but its size can be halved through UPX. It can also be an alternative to (Power|Pure|Free)Basic for small applications without the weight of .Net.
In addition to the AutoIt.chm help file — which is the offline version of the online doco —, the wiki, and the forum, information can also be found in Valuater's "Welcome to AutoIt 1-2-3", "Program on Windows Using FREE Tools" by Jayme Fishman (2015), "Learning to Script with AutoIt V3" by Alex Peters, updated by Brett Francis (2010), and Andy Flesner's AutoIt v3: Your Quick Guide (2007).
As of version 3.3.6.1, AutoIT consists in the following programs:
To install UDFs, if you're using SciTE4AutoIt3, it's better to create a new directory outside the AutoIT folder so that the files aren't affected when upgrading AutoIT. To tell SciTE to find those files, use Tools > SciTE Config, and fill the "User Include Folders" in the "General 1" tab.
It's a good idea to set the following option in all scripts: Opt('MustDeclareVars', 1)
#include <MsgBoxConstants.au3>
MsgBox($MB_OK, "Tutorial", "Hello World!")
Go to \Extras\Au3Record\, and launch Au3Record.exe to record an action that Au3Record will then save as source code that you can use in your scripts.
Caution: Code generated Au3Record isn't always reliable, as some functions won't work. YMMV.
Note: _WinWaitActivate() is not part of AutoIT; Its code found below must be included in the script.
Note: "AutoIt Recorder utility is not available from AutoIt Version 3.3.14.1." (source)
Use install\Au3Info.exe.
Check UIASpy - UI Automation Spy Tool
The WebDriver UDF makes it possible to interact with a web browser (Firefox, Chrome, etc.) through an API instead of its UI.
Important: All the required files above must be unzipped at the root of your "User Include Folder", ie. where you keep your personal UDF files, so that wd_demo.au3 can find them — It won't look in sub-directories.
The wd_demo.au3 is used to check that everything works OK, while wd_core.au3 and wd_helper.au3 contain code that you need to drive a browser.
As of April 2021, there seems to be no tutorial. To learn how to use the WebDriver UDF:
NO DOS https://www.autoitscript.com/forum/files/file/351-learn-to-program-using-free-tools-with-autoit/
NO TUTORIAL ON DOS https://www.autoitscript.com/autoit3/docs/
NO TUTORIAL ON DOS Learning to Script with AutoIt V3 (Last Updated 17 Feb 2010).zip
Autoit-1-2-3 http://www.autoitscript.com/forum/index.php?act=attach&type=post&id=10824
Run()
Run(@ComSpec & " /k c:\program files\deltacopy\rsync.exe -v")Just replace the /K with /C when it works to have the window closed automatically and look at the other options when you want the window not to appear at all.
RunAs
RunAsWait
RunWait
ConsoleRead
ProcessClose
ShellExecute
ShellExecuteWait
StderrRead
StdinWrite
StdioClose
StdoutRead
$oOutlook = ObjCreate("Outlook.Application")
https://www.autoitscript.com/forum/topic/126357-outlookex-udf-help-support/
After installing OutlookEX UDF per its Readme, run Outlook, and use the following script to read the data from its To-Do List panel, sorted through Last Modified:
;CTRL+A
Send("^a")
Sleep(3000)
;CTRL+C
Send("^c")
#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
ClipPut(_NowTime())
Local $sClipboard = ClipGet()
MsgBox($MB_SYSTEMMODAL, "Clipboard", $sClipboard)
Besides the Control*() functions, there are also: StatusbarGetText, WinActivate, WinGetClassList, WinMenuSelectItem.
ControlSend("Untitled - Notepad", "", "[CLASSNN:Edit1]", "This is some text")
ControlSetText("My Window", "", "[NAME:textBoxFolder]", "C:\Some\Folder")
ControlClick("My Window", "", "[ID:254]")
ControlClick("My Window", "", "[CLASS:Button; TEXT:Finish; INSTANCE:2]")
Note: ControlSetText() sometimes doesn't work as expected; If that case, try ControlSend() instead.
Launch the SciTE editor in install\SciTe\SciTE.exe, where you can copy-paste the action you just recorded with Au3Record.exe.
For $i = 5 To 1 Step -1
MsgBox($MB_SYSTEMMODAL, "", "Count down!" & @CRLF & $i)
Next
Use ";"
#comments-start
…
#comments-end
If using the AutoIT-provided SciTE editor, select the block of text, and hit Edit > Stream Comment
MsgBox(64, "My title", "My text")
Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
More information here.
Note: You may use Opt() as an alternative to AutoItSetOption().
AutoItSetOption ("WinTitleMatchMode",2)
Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced,
-1 to -4=Nocase
Func _WinWaitActivate($title,$text,$timeout=0)
$result = WinWait($title,$text,$timeout)
if $result = False Then
MsgBox(16,"Bad...","Window not displayed")
Exit(1)
EndIf
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
EndFunc
Sleep(1000) ; sleep for 1s
#include <Misc.au3>
CHECK MouseMove(@DesktopWidth/2, @DesktopHeight/2)
http://www.autoitscript.com/autoit3/docs/functions/ControlCommand.htm
http://www.autoitscript.com/autoit3/docs/functions/ControlSend.htm
http://www.autoitscript.com/autoit3/docs/functions/ControlFocus.htm
(only as last resort)
http://www.autoitscript.com/autoit3/docs/functions/Send.htm
http://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm
To set or refer to the content of a variable: (Const/Global/Local/Dim) $myvar = "test"
To refer to environment variables: @ComputerName
To require explicit declaration of variables: Opt("MustDeclareVars", 1)
To include files: #include <myfile.au3>
To include an external file into the AutoIT output EXE à la NSIS: FileInstall(Source,Destination[,flag])
The array.au3 UDF offers extended functions to handle arrays, eg. _ArrayDisplay($myarray)
For $index=1 to 1
Next
To pause for one second:
Exit
Exit(1)
Exit(2)
#include <SQLite.au3>
#include <SQLite.dll.au3>
Global $DB
_SQLite_Startup ()
$DB = _SQLite_Open("sqlite.db")
_SQLite_Exec($DB, "CREATE TABLE TABLE1 (Text);")
_SQLite_Exec($DB, "BEGIN;")
For $i = 1 to 1000 Step 1
_SQLite_Exec($DB, "INSERT INTO TABLE1 VALUES ('Some text');")
Next
_SQLite_Exec($DB, "COMMIT;")
_SQLite_Close($hDatabase)
_SQLite_Shutdown()
#include <Array.au3>
#include <SQLite.au3>
_SQLite_Startup() ; Load the DLL
If @error Then Exit MsgBox(0, "Error", "Unable to start SQLite, Please verify your DLL")
Local $sDatabase = @ScriptDir & '\SQLiteTestDatabase.db'
Local $hDatabase = _SQLite_Open($sDatabase) ; Create the database file and get the handle for the database
_SQLite_Exec($hDatabase, 'CREATE TABLE People (first_name, last_name);') ; CREATE a TABLE with the name "People"
_SQLite_Exec($hDatabase, 'INSERT INTO People VALUES ("Timothy", "Lee");') ; INSERT "Timothy Lee" into the "People" TABLE
Local $aResult, $iRows, $iColumns ; $iRows and $iColuums are useless but they cannot be omitted from the function call so we declare them
_SQLite_GetTable2d($hDatabase, 'SELECT * FROM People;', $aResult, $iRows, $iColumns) ; SELECT everything FROM "People" TABLE and get the $aResult
_ArrayDisplay($aResult, "Results from the query")
_SQLite_Close($hDatabase)
_SQLite_Shutdown()
To run a desktop shortcut:
AutoIT can be used to write graphical applications. As of 2018, there are two ways to do this: Either by writing your own code directly, or by using any of the numerous GUI creators such as the Koda GUI designer (which is included in the AutoIT installer.)
AutoIT supports the following widgets:
myscript..au3 (1) : ==> Unknown function name.: _WinWaitActivate("classname=TfrmPref","")
If you just copy/paste the output instead of what's actually saved in a file, you'll be missing some User-defined functions (UDF) that Au3Record relies on:
There is a bug with release 3.3 which uses "classname=myclass" instead of "[CLASS:myclass]".
Compile displays a dialog to set options, while Build doesn't.
No PDF or CHM for tutorial? https://www.autoitscript.com/autoit3/docs/
The Send() function sends a string to whatever window is active, ie. it's not possible to tell it to only send data to a specific window. So if you're using a loop, add a WinWaitActive() to make sure you're no sending stuff in a totally different window:
You must use "&", not "+":
Here's how to clear the clipboard, and copy data to it:
#include <Clipboard.au3>
The PCRE regex engine that AutoIT uses is single-line by default. If you need to find a pattern in a multi-line string, you must tell PCRE explicitely:
There is apparently no way to configure PCRE externely for the duration of a script, ie. without adding settings to every single pattern.
Here's how to extract the second part in a two-item string with a TAB delimiter:
https://www.autoitscript.com/forum/