From iMacros
Revision as of 01:18, 21 January 2010 by Mf (Talk | contribs)

Jump to: navigation, search

Plays a macro. After the macro has played all options that have been set with the iimSet command are reset. Use iimGetLastExtract to get the extracted text.

There are two fundamentally different ways of playing a macro using the iimPlay command. The first is to specify the filename (without the extension) of the macro in the String macro parameter. The other is to generate macro code on-the-fly in your program and pass it, preceded by CODE:, directly to iimPlay using the String macro parameter. Several commands in a macro generated on-the-fly must be separated by the CR (carriage return) symbol. These are vbNewLine or vbCrLf in Visual Basic or \r\n in C, C++ or C#.

If you start a macro via iimPlay which contains a TAG TYPE=SELECT... statement and the specified value is not in the drop down list then the iimPlay command returns an -251 error code. In the corresponding error message (see iimGetLastError) the maximum index is given. You can use this value, for example, to always select the last entry of a changing drop down list.


int ret_code = iimPlay ( String macro [, int timeout] )


  • String macro
    Either the macro's filename without the extension, a string holding macro commands or the macro code.

(1) iimPlay ("demo-download") - If you just supply the macro name, iMacros looks for the file in the standard macro folder (as specified in the Options dialog or iim.ini file).
(2) iimPlay ("c:\MyMacros\macro1.iim") - Full path
(3) iimPlay ("CODE:URL GOTO....") Example

  • int timeout
    The optional timeout value. If the command is not completed during this time span, the Scripting Interface returns a timeout error -3. No extraction data is returned in this case. The default value is 600 seconds. This is the timeout for the overall macro runtime. This value should not be confused with the timeout inside a macro, which is the timeout for a single macro step.. The iimPlay timeout is typically triggered by a browser crash, a browser freeze or if the macro runtime exceeds this value.

Error Handling

iimPlay returns a detailed error code for every problem encountered. Please see the Scripting Interface Return Codes and the general iMacros Error-Codes, which are transmitted via the iimPlay command back to the calling application.


Play a macro located in the Macros\ directory of your iMacros installation (Visual Basic Script example):

Dim imacros, iret 
Set imacros = CreateObject("imacros") 
iret = imacros.iimInit() 
iret = imacros.iimPlay("mymacro") 

Play some on-the-fly generated code (Visual Basic Script example):

Dim imacros, iret, mycode, myURL 

myURL = "http://www.iopus.com"  

mycode = "URL GOTO=" + myURL + vbNewLine 
mycode = mycode + "TAG POS=1 TYPE=FONT ATTR=TXT:<SP><SP>Online<SP>Store" 

Set imacros = CreateObject("imacros") 
iret = imacros.iimInit() 
iret = imacros.iimPlay("CODE:" + mycode)


In the iMacros for Firefox built-in Javascript Scripting Interface you have the option to add the relative path to the iimPlay command. Example: If your Javascript (JS) file is in the main directory, but the macros are in the "test1" subdirectory, then please use iimPlay ("test1/yourmacro"). (Note: This feature will be added to the general Scripting Interface in the near future, too.)