Macros are scripts which automate Komodo. They are stored in projects or toolboxes, and can be launched by double-clicking the macro icon, pressing an associated custom key binding, or by binding them to event triggers.
The Macros toolbar provides quick access for recording, running, and saving macros. To show or hide the toolbar, select View|Toolbars|Macros. You can also use the Tools|Macros menu items.
Macros can be created by recording keystroke and command sequences, or written from scratch in JavaScript or Python using the Macro API.
Recording is a simple method for creating a macro. Only keystrokes (not mouse movements) are recorded.
To record a macro:
Note: Though keystrokes in the Editor pane can be captured and recorded in this manner, several Komodo commands cannot. If your resulting macro does not replay certain operations, you may be able to add them manually by editing the recorded macro. Consult the Writing Macros section in conjunction with the Command ID List and the Macro API for further information.
To save the most recent macro:
Use the "New Macro" Properties dialog box to write macros in either Python or JavaScript. This dialog box has tabs for specifying key bindings and Komodo event triggers that invoke the macro automatically.
To add a macro:
Refer to the Macro API for information about writing JavaScript and Python macros in Komodo.
To run the most recently recorded macro, select Tools|Macros|Execute Last Macro. If the Macro Toolbar is open (View|Toolbars|Macro), click Macro: Run Last Macro.
To run a macro that has been saved to a project or toolbox, double-click the macro or use the key binding you have assigned to it. Alternatively, right-click the macro and select Execute Macro.
Macros can be dragged into any project, toolbox or folder. Right-clicking on a macro brings up a context menu with the following additional options:
Right-click on a macro and select Properties to view or edit the macro or configure the following properties.
Use the Key Binding tab to specify a key combination or sequence for invoking the macro. To add a new keybinding:
If the macro is in a toolbox, the assigned keybinding will always trigger the macro. If it's in a project, the keybinding will work only when that project is open.
The default macro icon can be replaced with custom icons. Komodo includes more than 600 icons, but you can use any 16x16-pixel image you wish.
To assign a custom icon to a macro:
To revert to the default icon for a selected macro, use the Reset button.
Macros that invoke and do not affect the current file should be run in the background to minimize interference with Komodo responsiveness. Macros that run in the background are run in threads (Python), or in a timeout (JavaScript). To set this option:
If a macro is not associated with a Komodo event, it can run either in the foreground or in the background.
Macros that perform "editor" functions or modify open files should always run in the foreground to "block" and prevent user interference. This prevents the user from moving the cursor and disrupting the macro currently in progress.
Macros can be configured to execute on certain Komodo events. When an event occurs (for example, a file is opened in Komodo), the macro is triggered.
Check to make sure macro triggers are enabled in the Projects and Workspace preferences. In the Triggering Macros area, select Enable triggering of macros on Komodo events, and then click OK.
To add a trigger to a macro:
Trigger macros run with an argument called "subject", available as a global variable within the macro. This variable references the ko.views.manager.currentView object for post-open, pre/post-save, and pre-close trigger macros. For post-close macros, it references the URI since the view object is empty at that point. For example, in a macro with an "After file open" trigger you could use:
alert("Just opened file " + subject.document.displayPath);
Komodo macros that use the event triggers "Before file save",
"Before file close", or "On shutdown", can make use of return values.
Macros that return that return a true value (e.g. True
in
Python, true
in JavaScript) can interrupt the process
under execution. For example, the following JavaScript macro
triggering "Before file save" prevents you from saving files on
Sunday:
var currentTime = new Date(); if (currentTime.getDay() == 7) { alert("Never on a Sunday!") return true; } else { return null; }
Komodo's Vi emulation offers a command-line mode. Entering ':' opens a text box for entering commands. To access a macros from this mode, create a toolbox folder named Vi Commands and move or copy the macro into it. Type the macro name in the Vi command text box to run it.