UserGuide

IDE Scripting

From Xojo Documentation

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.

IDE Script Editor

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 + Shift + #
Open / Edit Cmd + Opt + Ctrl + # Alt + Ctrl + Shift + #

IDE Scripts can use Xojo language commands in addition to the commands described in the IDE Scripting Commands sections.

IDE Scripting

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.

Example Scripts

There are several example IDE Scripts included with Xojo. Look in the Examples/Advanced/IDE Scripting folder. Some examples include:

  • AddCommentHeader
  • BuildAllDesktop
  • CountDebugRuns
  • CreateConstant
  • EncryptItems
  • Reload Project
  • SaveAll
  • SetShortVersion

See Also

Refer to these topics for additional information on scripting: