How to Use Batch Actions

 
Sometimes, you'd like to make AeTrayMenu perform multiple actions when a menu item is clicked. Normally, you would write a batch (.bat) file and then run that batch file. However, AeTrayMenu gives you a way to include those batches in the configration file, in order to keep your configuration centralized: multi actions.

How "Multi" Actions Work

First, you assign the multi action to a menu item, like this: [Menu.Left] Type: item; Caption: "Run Multiple Commands"; Action: multi; Actions: MultiActions This tells AeTrayMenu to look in a section called [MultiActions] for the actions that have to be performed when the user chooses the menu item.

In such a batch actions section, you list the actions. It is like listing a menu, but without the Type, Caption and Glyph parameters. For example: [MultiActions] Action: run; FileName: "%Windows%\Notepad.exe" Action: run; FileName: "%Windows%\Calc.exe" This example opens both Notepad and Calculator.

Preventing Simultaneous Execution

It is possible to suspend execution of the next action until the current item has completed. In the example above, AeTrayMenu tells Windows to run Notepad, and right after that issues the command to run Calculator. What if you want to run Notepad, and after Notepad has closed run Calculator?

For those situations, the actions run, shellexecute and service have the waituntilterminated flag. You could for example enter: [MultiActions] Action: run; FileName: "%Windows%\Notepad.exe"; Flags: waituntilterminated Action: run; FileName: "%Windows%\Calc.exe" in the configuration file, so that Calculator will be run after Notepad has closed.

Another flag, waituntilinputidle, is supported only by run and shellexecute. It suspends execution of the batch actions until the program/document that is executed is ready for user input.

Ignoring errors

If one of the actions in the batch causes an error, the execution of the batch will stop. You can prevent this by using the ignoreerrors flag. An example: [MultiActions] Action: service; Service: apache2; ServiceAction: startresume; Flags: ignoreerrors Action: service; Service: mysql; ServiceAction: startresume; Flags: ignoreerrors A good example of where this may be useful is a service controller. Suppose you can't be sure that all services exist, but you want to be able to start all existing services. You'd have to somehow dynamically adapt the above section depending on which services exist and which don't. However, by using the ignoreerrors flag, you can just attempt starting them all, without bothering about error messages.

Service Handles

There's one tricky thing about working with AeTrayMenu: you have to be careful when running programs that modify service configurations while the traymenu is running. AeTrayMenu keeps handles open to all services it is told to control, so that e.g. uninstaling the services will "mark it for removal upon reboot" instead of removing it immediately. When doing this from external applications, you can use the -quit command-line parameter, but what to do when attempting to uninstall a service from within the traymenu itself?

For this purpose, two special actions are available: closeservices and resetservices. closeservices will let the traymenu close its handles, while resetservices will re-open them (if possible). An example of their usage: [MultiActions] Action: closeservices Action: run; FileName: "%Apache%\bin\Apache.exe"; Parameters: "-k uninstall" Action: resetservices Always be sure to call resetservices as well, otherwise the user won't be able to control any of the services!

seealso (1K) See Also
Batch Actions Sections
"Multi" Action
List of Available Actions