Introduction to IDE scripting
IDE scripting
IDE Scripting is the ability to create scripts that allow you to manipulate the Xojo user interface (IDE). IDE Scripts use the XojoScript engine and support the Xojo programming language, a subset of functions and other IDE Scripting Commands.
Creating an IDE script
To create an IDE script, select IDE Scripts > New IDE Script from the File menu. This opens the XojoScript Editor. You can open multiple IDE Script editors, each with their own scripts.
In this editor you write code using the XojoScript scripting language, which consists of Xojo programming language commands (such as If..Then or For..Next). You can also use special IDE Scripting commands such as DoCommand, DoShellCommand and more.
All the IDE Scripting commands are listed in the IDE Scripting Commands section.
This simple script saves the current project:
Speak("Saving file.")
DoCommand("SaveFile")
To run the script, click the Run button on the Xojo Script Editor toolbar.
Saving and loading IDE scripts
IDE Scripts are saved as text files and are not included within the project. To save a script, use File > Save or Save As. To load an existing script into the Script Editor, use File > Open.
You can also add scripts to the IDE Scripts submenu. Clicking a script in this menu immediately runs it; it does not open in the Script Editor. To open it into the Script Editor hold down Option (on Mac) or Control (on Windows/Linux). To have a script appear in this submenu, add the saved script to the Scripts folder alongside the Xojo app or add it to a Scripts folder you create alongside your project file. There are also corresponding shortcut commands to run or open the scripts:
Command |
Mac |
Windows / Linux |
---|---|---|
Run |
Cmd Option # |
Ctrl Alt # |
IDE Scripts can use Xojo language commands in addition to the commands described in the IDE Scripting Commands sections.
Recording a script
On the XojoScript Editor toolbar is a Record button. When pressed, any commands in the IDE that have a corresponding script command are recorded when they are used. To try this, click the Record button (the text changes to "Stop Recording") and then select File > Open to open a project.
You 'll see the this command appear in the XojoScript Editor:
DoCommand("OpenFile")
Now click Run to run your project (not the script) and you 'll see command appear in the editor:
DoCommand("RunApp")
As you use the IDE, any actions that have corresponding script commands will appear in the XojoScript Editor as they are recorded. All these recordable commands are listed on the DoCommand page.
Assigning a shortcut key
You can assign a keyboard shortcut to a script by placing a comment at the top of the script file with the shortcut defined.
Example: ' KeyboardShortcut = CMD-OPT-SHIFT-Y
See the DesktopMenuItem.ShortCut property for valid keys.
Example scripts
You can learn more about IDE scripting be experimenting with examples which you can download here
.
Some of the included examples are:
AddCommentHeader
BuildAllDesktop
CountDebugRuns
CreateConstant
EncryptItems
Reload Project
SaveAll
SetShortVersion
See also
Refer to these topics for additional information on scripting: