Start other macro

Syntax

mac[+|-] [macro] [command] [arg1 ...]

 

Parts

macro - QM item name (if string) or id (if numeric). Default: "" - current item (in editor). Note: item name must be enclosed in double quotes, unless it is a variable.

command - some string or number. How it is interpreted depends on item type.

If macro is command is interpreted as
macro or function string to be stored into the _command variable. If command was numeric, it is converted to string.
toolbar window to be associated with the toolbar. Can be window name or handle.
menu menu item label. Instead of showing menu, that item is executed.
T.S. menu not used.

arg1 ... - up to 31 string or numeric values. If macro is macro or function, it receives them as arguments (use function).

 

Options:

+ open macro in editor (don't run) ;
- end this item (item that executes mac) and start macro.
Default continue executing this item and start macro. If both items are macros (not functions, etc), macro starts when this macro ends, else, if only macro is macro, is applied "If a macro is running" property.

 

Remarks

Launches macro, function, menu, toolbar or T.S. menu. Unlike function call, macro runs asynchronously, in new thread.

 

If the macro does not exist, is generated run-time error. The macro does not have to exist when this (currently running) macro starts.

 

If macro string begins with \, it is interpreted as QM item path. For example, to launch macro "Next" that is in "Mouse" folder, you can use "\Mouse\Next".

 

Actually mac is function, although the return value is rarely used. The return value depends on item type.

If macro is mac returns
macro or function Thread handle. You can use it, for example, to wait until the macro exits. Don't close the handle. It will be 0 if both items are macros.
toolbar Toolbar window handle. Read more.
menu If used as function (like variable=mac("menu")), mac waits until the menu is closed. It then returns a nonzero value if an item clicked, or 0 if not. If used like mac "menu", it does not wait. Read more.
T.S. menu 0

 

Tips

To quickly insert mac command, you can drag and drop.

 

See also: functions, net, run text as macro, wait for macro, find macro, programmatically create macro.

 

Examples

mac "Macro5" ;;run macro "Macro5"
mac "\Folder\Macro5" ;;run "Macro5" that is in "Folder" folder
mac- "Macro5" "a" ;;end current macro and run "Macro5". Also, send string "a" as command.
mac "Func" "" "some string" 1 55.5 ;;asynchronously run function "Func" and send three arguments
 
 Get id of "Macro5" and run it:
int i = qmitem("Macro5")
mac i
 
 If window "Notepad" exists, create toolbar "Bar" and associate it with "Notepad":
mac "Bar" "Notepad"

 Asynchronously run function "Function" and wait until it exits:
int hThread=mac("Function")
wait 0 H hThread