Posted by Paul Lefebvre
Did you know that you can use the IDE Scripting feature of Xojo to automate many tasks?
What is IDE Scripting? It is Xojo code that can manipulate the Xojo IDE itself.
File->IDE Script->New IDE Script opens a window where you can create IDE Scripts. Here is a simple one to display a message in a dialog:
You can do all sorts of things with IDE Scripts from creating and modifying project items to changing build settings. Take a look at the following examples.
This small example adds a comment header to the top of the currently visible method:
Dim header As String
header = "// Copyright 2013 Acme, Inc."
Text = header + EndOfLine + EndOfLine + Text
Convert to Constant
Here is an example that does some string manipulation to create an inline constant for the selected text in the code editor:
Dim constantText As String
constantText = SelText
Dim newConstant As String
newConstant = "Const kValue = """ + constantText + """"
SelStart = SelStart-1
SelLength = SelLength + 2
SelText = "kValue"
Text = newConstant + EndOfLine + EndOfLine + Text
This script sets the ShortVersion to match the version numbers specified in Shared Build Settings:
Dim version As String
version = PropertyValue("App.MajorVersion") + "." + _
PropertyValue("App.MinorVersion") + "." + _
PropertyValue("App.BugVersion") + " (" + _
PropertyValue("App.NonReleaseVersion") + ")"
PropertyValue("App.ShortVersion") = version
Save Open Projects
This script saves all the open projects:
Dim saved As String
Dim comma As String
Dim i As Integer
For i = 0 To WindowCount-1
saved = saved + comma + WindowTitle(i)
comma = ", "
Print("Saved: " + saved)
Once you've created scripts that you use often, you can save them and put them in the Scripts folder alongside the Xojo IDE or alongside your project file. These scripts then appear in the IDE Script submenu. When you select them, they run automatically.
The above examples are all included with Xojo 2013 Release 4 for you to try:
Also the IDE Scripting section of the User Guide (Book 3: Framework, Chapter 9: Building Your Applications, Sections 3 and 4) has been enhanced to cover all the IDE Scripting commands that are available, so be sure to check it out.
I also encourage you to take a look at the Code Format IDE Script created by Jeremy Cowgar. It's a great example of how powerful an IDE Script can be!
You can also use IDE Scripting with Build Automation, but that is a topic for another blog post.