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:
Print("Hello, world!")
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.
Comment Header
This small example adds a comment header to the top of the currently visible method:
Dim header As Stringheader = "// 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 StringconstantText = SelText Dim newConstant As StringnewConstant = "Const kValue = """ + constantText + """" SelStart = SelStart-1SelLength = SelLength + 2SelText = "kValue" Text = newConstant + EndOfLine + EndOfLine + Text
Set ShortVersion
This script sets the ShortVersion to match the version numbers specified in Shared Build Settings:
Dim version As Stringversion = 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 SelectWindow(i) saved = saved + comma + WindowTitle(i) DoCommand("SaveFile") comma = ", " Next Print("Saved: " + saved)
Other Tips
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:
Examples/Advanced/IDE Scripting
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.