How to Run iMacros from Batch file

Lets begin with a short description of iMacros plugin. This plugin lets you record and replay repetitious work.
Some features of the iMacros plugin are the following:

  • Automatically fill-out forms just like an end-user would. You can easily download and upload of text, images, files and web pages, handle PDF files, or take screenshots.
  • Import or export data to and from web applications using CSV & XML files, databases, or any other source.
  • Update Excel and Access from the web.

More detailed description can be found at the iMacros official page which is: http://www.imacros.net/

Running from Batch files

Instead of running iMacros from the browser extension there is the possibility of running the scenario or multiple scenarios through batch files.

Assuming that the iMacros scenarios are located in the folder C:\iMacros\Scenarios

We can create our batch files in a different folder C:\iMacros\batch

Our first batch file will be in the following form:

@echo off
echo echo Running batch file: %~n0%~x0

@setlocal
@set pf=%ProgramFiles%

SET BATCH_FILE_DIR=%~dp0

REM The following line will run the iim .scenario from the folder Scenarios
"%pf%\Ipswitch\iMacros\iMacros.Sidebar.exe" -silent -macro "%BATCH_FILE_DIR%\..\Scenarios\Payment.iim"

REM Following line will check if the iMacro completed successful then will direct to :ok command
if %errorlevel% == 1 goto ok
REM Following line will check if the iMacro did not completed successfully then will direct to :error command
if NOT %errorlevel% == 1 goto error

REM Following line will print in the batch file that iMacro completed successfully and also will write in the output.log the details of the user who run the scenario, status, date and time.
:ok
echo Macro completed successfully!!
timeout /t 5
echo -------------------------------------------------------------------------------------------- >>  %BATCH_FILE_DIR%\output.log
echo SUCCESS!! Payment proceeded Username:%USERDOMAIN%/%USERNAME%  Date:%date% Time:%time%  Filename:%~n0 >>  %BATCH_FILE_DIR%\output.log
goto end

REM Following line will print in the batch file that iMacro  did not completed successfully and also will write in the output.log the details of the user who run the scenario, status, date and time.
:error
echo Error encountered during replay.
echo -------------------------------------------------------------------------------------------- >>  %BATCH_FILE_DIR%\output.log
echo FAIL!! Payment Failed Username:%USERDOMAIN%/%USERNAME% Error-Code:%errorlevel%  Date:%date% Time:%time%  Filename:%~n0 >> %BATCH_FILE_DIR%\output.log
timeout /t 5
echo Please see http://wiki.imacros.net/Error-Codes
echo for a detailed description of error codes.

:end

While clicking the batch file will run and wait till the iMacro execution.

2 Replies to “How to Run iMacros from Batch file”

  1. Hi, is your imacros a personal edition or professional edition?

    I’m having trouble on this line. My batch file is calling the program but it appears to not activate any macro

    “%pf%\Ipswitch\iMacros\iMacros.Sidebar.exe” -silent -macro “%BATCH_FILE_DIR%\..\Scenarios\Payment.iim”

Leave a Reply

Your email address will not be published. Required fields are marked *