AutoScript is a tool designed to help you write PowerScript code more quickly by providing a lookup and paste service inside the Script editor.
If you are not sure what the name or syntax of a function is or what the names of certain variables are, AutoScript can show you a list to choose from and paste what you need right into the script. If you can remember part of the name, start typing and press a shortcut key (if assigned) (or do nothing if automatic pop-up is turned on). If you cannot remember the name at all, turn automatic pop-up on, and place your cursor at the beginning of a new line or in white space.
Where you use AutoScript
You can use AutoScript in different contexts:
-
When you can remember part of the name and you want AutoScript to finish typing it for you or show you a list of alternatives.
-
When you cannot remember the name or you just want a list. AutoScript options can help you narrow the list if you do not know the name but you do know the type you are looking for.
-
When you want a list of the properties and/or functions and events that apply to an identifier followed by a dot.
Two ways to use AutoScript
AutoScript can pop up a list automatically when you begin typing, or when you request it:
-
Turn automatic pop-up on to have AutoScript pop up the list or complete what you are typing. See Using automatic pop-up.
-
Invoke AutoScript when you need it by pressing the shortcut key you assigned to the Edit > Activate AutoScript menu item when you have typed one or more characters. See Creating shortcut keys. Pressing the shortcut key activates AutoScript only once. It does not turn automatic pop-up on.
If there is more than one property, variable, method, or statement that could be inserted, AutoScript pops up an alphabetical list of possible completions or insertions.
① An icon next to each item indicates its type. The following screen includes functions, events, variables, snippets, classes, and keywords.
② The types are also displayed as selectable items at the bottom of the window, and the list can be filtered according to the selected types. The item filters are shown only when you enable the "Show completion item filters" option in the Design > Options menu > AutoScript tab page.
③ QuickInfo of the selected item displays alongside the window, providing information of the item type, item name, parameter type, return type, and if a function is overloaded, text like "(+1 overload)" will be displayed (④).
When you are in the following contexts:
-
When you have started typing a variable or method name or the beginning of a PowerScript statement
-
When you have typed the name of an object followed by a dot
-
When the cursor is at the beginning of a new line or in white space
-
For more contexts, refer to the next section.
The following items may be included in the list:
-
Arguments -- for the current function or event.
-
Local Variables -- defined in the current script.
-
Instance Variables -- defined for and associated with an instance of the current object or, after a dot, variables associated with the object preceding the dot.
-
Shared Variables -- defined for the current object and associated with all instances of it.
-
Global Variables -- defined for the current application.
-
Properties -- for the current object or, after a dot, properties for the object preceding the dot. Includes controls on the current window.
-
Methods -- Functions and events for the current object or, after a dot, functions and events for the object preceding the dot.
-
Statement Templates -- PowerScript statement templates for each type of IF, FOR, CHOOSE CASE, TRY, or DO statement with comments indicating what code should be inserted.
Contexts triggering the list
For example, in the Open event, if you type "a", the auto-completion list pops up and contains a list of PowerScript functions, events, variables, classes, and keywords, such as the "abs" function, the "accessiblerole" variable, the "activate" event, etc.
The tooltip on the right side shows information on the current item.
If the list is long, you can filter the items by selecting the item types (e.g., function, event, variable, snippet, class, keyword etc.) at the bottom of the list window.
When AutoScript adds the parenthesis automatically, the cursor is placed based on whether the function has parameters. When the function has parameters, the cursor stays inside the parentheses, when the function has no parameters, the cursor stays behind the parentheses.
For example, when you type "cpu" and press the Tab or Enter key, it will automatically input "cpu()" and the cursor will stay behind the parentheses.
For another example, when you type "apply" and press the Tab or Enter key, it will automatically type "applytheme", and the cursor will stay inside the parentheses because the function requires parameter, and a tooltip will display the parameter type.
When entering a function name and typing the left parenthesis, the right parenthesis is automatically added.
When you type "String(", it will automatically input "String()" and show that it has three overloaded functions. If you enter the first parameter as 12345, type a comma, and then enter a single quote for the second parameter; at this point, a pair of single quotes is automatically added, and the tooltip is always displayed.
When you start typing inside the parentheses for a function, the auto-completion list pops up.
Typing the left parenthesis for the function will automatically insert the right parenthesis.
For example, when you type "cpu(", it will automatically add the right parenthesis, changing it to "cpu()".
When you type a window name or a menu name followed by a dot, the auto-completion list pops up.
When you type a parameter name followed by a dot in the function body, the auto-completion list pops up.
Case sensitivity
If you have set the PasteLowerCase PB.INI variable to 0 as described in Pasting statements, AutoScript always pastes uppercase characters. Otherwise, AutoScript always pastes lowercase characters.
The case of any characters you have already typed is preserved. For example, if you are using AutoScript to complete a function name and you want to use mixed case, you can type up to the last uppercase letter before invoking AutoScript. AutoScript completes the function name in lowercase characters and pastes an argument template.
Pasting an item into the script
To paste an item into the script, press Tab or Enter or double-click the item. Use the arrow and page up and page down keys to scroll through the list. If the item is a function, event, or statement, the template that is pasted includes descriptive comments that you replace with argument names, conditions, and so forth. The first commented argument or statement is selected so that it is easy to replace. You can jump to the next comment by selecting Edit > Go To > Next Marker.
Go to next marker
You can use Edit > Go To > Next Marker to jump to the next comment enclosed by /* and */ anywhere in the Script editor, not just in AutoScript templates. For the steps to create a shortcut for this menu item, see Customizing AutoScript.
If nothing displays
AutoScript does not pop up a list if the cursor is in a comment or string literal or if an identifier is complete. If neither of these conditions applies and nothing displays when you select Edit > Activate AutoScript, there may be no appropriate completions in the current context.
You can have AutoScript pop up a list automatically whenever you start typing. To do so, check the "Automatic Popup" and "Show auto-completion list after a character is typed" boxes on the Design > Options menu > AutoScript tab page.
-
Automatic Popup -- Select if you want the code auto-completion list to pop up automatically when you begin typing. This option must be turned on for the other options on this tab to take effect.
-
Show auto-completion list after a character is typed -- Select if you want the code auto-completion list to pop up automatically after you type a character (including a dot). If you deselect this option, the code auto-completion list will pop up only when you have typed an identifier followed by a dot.
-
Show auto-completion list after a character is deleted -- Select if you want the code auto-completion list to update automatically to reflect the changes when you delete a character, ensuring that suggestions are always relevant to the current state of the code.
-
Show completion item filters -- Select if you want to show the filters (e.g., function, event, variable, snippet, class, keyword) at the bottom of the list window and the auto-completion list will filter items according to the selected types. It helps developers easier to find and select the right code element from a large list of suggestions.
Using AutoScript only with dot notation
You can also have AutoScript pop up a list automatically only when you have typed an identifier followed by a dot. To do so, check the "Automatic Popup" box but uncheck the "Show auto-completion list after a character is typed" box on the AutoScript options page.
You can also use a shortcut key to invoke AutoScript only when you need it. Pressing the shortcut key activates AutoScript only once. It does not turn automatic pop-up on.
To modify or create shortcut keys for using AutoScript
-
Select Tools > Keyboard Shortcuts from the menu bar and expand the Edit menu in the Keyboard Shortcuts dialog box.
-
Scroll down and select Activate AutoScript and type a key sequence, such as Ctrl+space.
-
Expand the Go To menu, select Next Marker, and type a key sequence, such as Ctrl+M.
After you click OK, the shortcuts display in the Edit menu.