Search code examples
javascriptbatch-fileimacros

How to Loop imacro script using batch file


My code looks like this in .bat file

start /B "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" imacros://run/?m="loop-google-ad-word.iim" -loop 3
timeout /t 120

But problem is I am not able to loop my loop-google-ad-word.iim script 3 times from batch file it runs just once normally.

I referred http://wiki.imacros.net/Example-Batchfile.bat here and did similarly. Also referred iMacros randomly stops in a loop but it does not loop

Any related suggestions are appreciated. Thanks in advance.


Solution

  • The above code helps me to loop batch file so in this loop I also added the code to delete 1st row of csv file from which my imacro reads data, so automatically imacro will get next row data at each loop.

    Also No. of times it should loop i have made dynamic depending on the lines in my csv file. So it first counts no. of lines and then passes it to for loop %cnt%

    @echo It will count no.of lines in file and pass the count 2for loop
    set file=C:\Users\account\Documents\iMacros\adwords-filename.csv
    set /a cnt=0
    for /f %%a in ('type "%file%"^|find "" /v /c') do set /a cnt=%%a
    echo %file% has %cnt% lines
    timeout /t 5
    
    @echo Loop starts now-------------------
    for /L %%A in (1,1,%cnt%) do (
        @echo call macro script
        start /B "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" imacros://run/?m="loop-google-ad-word.iim"
        timeout /t 60
    
        @echo delete 1st line of csv file at each loop
        set "csv=C:\Users\account\Documents\iMacros\adwords-filename.csv"
        more +1 "%csv%" >"%csv%.new"
        move /y "%csv%.new" "%csv%" >nul
    )