Startup script
When Code::Blocks finishes loading, it tries to load a script named startup.script. If it is found it then tries to execute the "function main()" inside it (if there). The user can edit this script to run arbitrary customization commands on application startup.
The shipped startup.script just logs its presence in the application's debug log.
function main() { Log(_T("Running startup script")); }
Example
As an example, you could register some scripts you have written and bind them to Code::Blocks' menus.
To do this, you will need to access the application object. It provides the RegisterScript function which comes handy for our little example :).
First thing you need to do is either:
- edit the global startup script (which can be found in the share/codeblocks/scripts subfolder of the folder you installed Code::Blocks, or
- create you own startup.script in your home folder (if Code::Blocks "sees" the script in your home folder, it will always favor it over the globally installed one). For unix systems this folder would be "~/.codeblocks/share/codeblocks/scripts" while for windows XP "C:\Documents and Settings\username\Application Data\codeblocks\Share\codeblocks\scripts".
Now, let's edit our startup script:
function main() { Log(_T("Running startup script")); // register a script with Code::Blocks' menus App.RegisterScript("sample.script", "Scripts/Sample script"); }
That wasn't hard, was it? We added a single line which will add a menu "Scripts" in the menu bar. Inside this "Scripts" menu it will add a "Sample script" item. When you click on this item, the script "sample.script" will be executed. Simple :).
All you have to do now, is create the "sample.script" file in the same folder. Here's an example:
// A sample script ShowMessage(_T("Hello from inside the sample script!"));
And don't forget that Code::Blocks conveniently allows you to edit the "sample.script" at any time. All you have to do is keep SHIFT pressed while clicking on the "Sample script" menu item ;).