Batch File: Load Firefox, Run Macro(s), Close

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
1tane1
Posts: 10
Joined: Thu Jan 03, 2013 9:20 am

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by 1tane1 » Thu May 16, 2013 1:49 pm

Is it possible to write a code to VBA in order excel to run an imacro?
wviswildandwonderful
Posts: 21
Joined: Sat Aug 22, 2009 6:35 pm

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by wviswildandwonderful » Mon Aug 19, 2013 6:08 pm

I have searched everywhere on the internet and there sdoesnt seem to be a workable answer to this! David Poor's scripts USE to run flawlessly several years ago... but for some reason it no longer works (for me, on my computer)! Is it the newer versions of windows? I dont know enough about programing to know the details..... What I do know is that a few years ago this post was working and relevant ... now there doesnt seem to be a batch file that can launch firefox, play one macro, wait for it to finish an then move onto anther macro!

Currently I can get this script to run ONE macro:

Code: Select all

	
    @ECHO ON
    ECHO
    ECHO You have 5 sec to close this Window to prevent the Macro from running...
    timeout 5
    ECHO Start Firefox and wait another 10 seconds...
    start /B "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
    timeout 10
    ECHO Now running the macro (in a 2nd Tab)...
     "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "imacros://run/?m="MYMACRO1.iim"

	rem Macro Execution completed
    ECHO FINISHED!
... the above code came from "chivracq" in this post http://forum.imacros.net/viewtopic.php?f= ... 52&p=53329

However I can not find a way to do as David Poor had originally done... Launch Firefox, Play Macro1-wait for it to finish, close... then play MACRO2-wait for it to finish, close... and so on!

Right now my only work around is to put ALL of the macros into one file and run the batch file.. which isnt good:
(1) the file is over 5000 lines long
(2) longer files seem to produce more stalls or errors!


Looping, time out and wait seconds wont work because each file varies and its immpossible to know how long it will take each one to run.

Every example I have scoured from the internet - results in multiple firefox windows all running at the same time.

.......... Any progamming wizards wanna spell it out for me? Please!
Last edited by wviswildandwonderful on Tue Aug 20, 2013 5:57 am, edited 1 time in total.
davidpoor
Posts: 33
Joined: Fri May 23, 2008 8:45 pm
Contact:

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by davidpoor » Mon Aug 19, 2013 6:51 pm

Exactly what do you mean by "it no longer works!"?

If you want me or anyone else to take a stab at your question, we really need to replicate your problem before we start so please provide as much information as you can on the differences between then and now.

Have you changed your OS? If so, what version of Windows were you running before and what version are you running now?

Have you tried the original test script? Do you have a simple test script that no longer works?

Can you post any error message(s) that you get?

ddsp
wviswildandwonderful
Posts: 21
Joined: Sat Aug 22, 2009 6:35 pm

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by wviswildandwonderful » Tue Aug 20, 2013 12:13 am

davidpoor wrote:Exactly what do you mean by "it no longer works!"?

If you want me or anyone else to take a stab at your question, we really need to replicate your problem before we start so please provide as much information as you can on the differences between then and now.

Have you changed your OS? If so, what version of Windows were you running before and what version are you running now?

Have you tried the original test script? Do you have a simple test script that no longer works?

Can you post any error message(s) that you get?

ddsp
Wow, thanks... I didnt expect a reply from "the man" himself!

When I first stumbled upon iMacro for firefox, I believe it was 2009 or 2010. I followed your directions to the "T" and it worked like a charm! I am not a programer by any stretch of the imagination , so I was THRILLED to find your instructions. I used it for over a year (without so much as even a bump)... I believe I had Firefox 3.6 or 4.1 with Windows 98.

My mother became very ill and required my full attention, so I basically did not use the script or imacros for over a year... Then in mid 2012 I decided to dig out my original copied files and pick up where I had left off. Nothing fancy, Basic Fill and submit stuff.

I copied the files onto my Windows 7 laptop, using firefox 14.0.1. (also tried the newest 22.0 version) and tried to run the batch file just as I had back then.

The copy I had in my files was this:

Code: Select all

     @ECHO OFF
    REM     ** Be sure to set the correct paths for Firefox **
    ECHO   Set parameters for FireFox to allow scripts to close macros
    cd "C:\Program Files\Mozilla Firefox\greprefs\"
    COPY all_allowClose.js all.js > junk.txt

    ECHO   Use Load-iMacro web page to launch js file after Firefox is loaded
    "C:\Program Files\Mozilla Firefox\"
    
	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro1.js
	
	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro2.js
	
	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro3.js

	
    ECHO   Reset parameters for FireFox to disallow scripts to close macros
    cd "C:\Program Files\Mozilla Firefox\greprefs\"
    COPY all_disallowClose.js all.js > junk.txt

    REM  Back to where we started: Change as needed
    CD C:\
1st I changed this line: "C:\Program Files\Mozilla Firefox\"
To this: "C:\Program Files (x86)\Mozilla Firefox\"

Then I realized there was no longer a grepref, so I deleted that ... So now my batch file looks like this:

Code: Select all

    @ECHO ON
    ECHO   Use Load-iMacro web page to launch js file after Firefox is loaded
    "C:\Program Files (x86)\Mozilla Firefox\"
    
	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro1.js
	
	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro2.js
	
	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro3.js


    CD C:\
My js file is exactly as it was when I saved a copy in 12/2010:

Code: Select all

    /*  DemoProcessAndClose.js                                           Version 1.0    */
    /*  Demo macro for Launch-iMacro.html                        May 30, 2008    */


    //  Use try/catch/finally for all main processing


    var report="mymacro1.js \n";
    try
    {
       report += "Navigate to specific site \n";
       iimPlay("mymacro1");
    }
    catch (err)
    {
       report += "**ERROR**: catch processing\n";
       report += err+"\n";
    }
	//alert(report);
    //  CLOSE FIREFOX
    //  under ff 2 you have to manually change C:\Program Files\Mozilla Firefox\greprefs\all.js
    //  set about:config dom.allow_scripts_to_close_windows to true
    setTimeout("window.open('','_parent','');window.close();",2000);
I didnt even try to clean up the remarks, I just figured the less I messed with it the better!

My macro file looks like this:

Code: Select all

VERSION BUILD=200003
TAB T=1     
TAB CLOSEALLOTHERS  
URL GOTO=http://www.iopus.com/imacros/demo/v6/f1/form.asp  
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:TestForm ATTR=NAME:Name CONTENT=Tom<SP>Tester 
'We manually changed the TAG command from using the postion of a value (e. g. "1") 
'to using its real name, e. g. "Pizza"
TAG POS=1 TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:main CONTENT=$Pizza
TAG POS=1 TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:drink CONTENT=$Water
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:TestForm ATTR=NAME:C7&&VALUE:ON CONTENT=YES 
TAG POS=1 TYPE=SELECT FORM=NAME:TestForm ATTR=NAME:dessert CONTENT=$Apple<SP>Pie:$Fruits 
TAG POS=1 TYPE=INPUT:RADIO FORM=NAME:TestForm ATTR=NAME:Customer&&VALUE:Yes CONTENT=Yes 
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:TestForm ATTR=NAME:Reg_code CONTENT=demo123 
TAG POS=1 TYPE=TEXTAREA FORM=NAME:TestForm ATTR=NAME:Remarks CONTENT=Hi!<BR><LF><BR><LF>iMacros<SP>fills<SP>forms<SP>;-)<BR><LF><BR><LF>Tom
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:TestForm ATTR=NAME:SendButton&&VALUE:Click<SP>to<SP>order<SP>now  
WAIT SECONDS=5
URL GOTO=http://www.iopus.com/imacros/home/msg/ok.htm 
I tried to execute the batch file and it just flashed the back dos window and went away... nothing ran.

I took the exact same files and loaded them onto an old desktop thats running windows xp, changed the firefox loaction again and it works! however that old dinasaur of a computer - firefox freezes, crashes, etc.. useless to me. I tried tweeking firefox in the about: config still was using 300,000 in the task manager. That old computer is XP, firefox 4.0.1

So I decided to uninstall my firefox and install 4.0.1 on this laptop... still no progress.

Like I said, Im not a programmer, so I really am not sure what Im doing or not doing. I only was able to acomplish what I was doing back in 2009 and 2010 thanks to the instructions that were laid out here.

Since then I have finally went with this code:

Code: Select all

	
    @ECHO ON
    ECHO
    ECHO You have 5 sec to close this Window to prevent the Macro from running...
    timeout 5
    ECHO Start Firefox and wait another 10 seconds...
    start /B "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
    timeout 10
    ECHO Now running the macro (in a 2nd Tab)...
     "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "imacros://run/?m="mymacro1.iim"

	rem Macro Execution completed
    ECHO FINISHED!
While it DOES work on my windows 7 ... I still am unable to find a way to load, play to finish, close and then load the next macro. I have tried various things suggested all over the internet and most either dont load at all or load all macros at one time. Here is a recent discussion I had with another forum about it: http://stackoverflow.com/questions/1815 ... -finish-th .... but still can not get any to work like your original post.

I truely appreciate your assistance.
Tammy

Windows 7 Home Premium Edition
Acer, Aspire Laptop, 64 Bit
Firefox 14.0.1
Imacros for Firefox 8.2.4
chivracq
Posts: 8871
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by chivracq » Wed Aug 21, 2013 2:11 am

My 2 cents..., what about launching your MyMacro1.iim + MyMacro2.iim etc with PUSH in some RunAllMacros.js (launched from the Batch File) like in 'Self-Test.js'...?

I'll give it a try myself...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
wviswildandwonderful
Posts: 21
Joined: Sat Aug 22, 2009 6:35 pm

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by wviswildandwonderful » Wed Aug 21, 2013 7:28 pm

chivracq wrote:My 2 cents..., what about launching your MyMacro1.iim + MyMacro2.iim etc with PUSH in some RunAllMacros.js (launched from the Batch File) like in 'Self-Test.js'...?

I'll give it a try myself...

Im not sure what to do with the js file? Do I call it from task manager?

I tried this:

(found on another board)

Code: Select all

	
    @ECHO ON
cd C:\Program Files (x86)\Mozilla Firefox
start firefox.exe 
ping -n 05 127.0.0.1>nul
start /wait firefox.exe imacros://run/?m=mymacro1.iim
start /wait firefox.exe imacros://run/?m=mymacro2.iim
start /wait firefox.exe imacros://run/?m=mymacro3.iim
	



	rem Macro Execution completed
    ECHO FINISHED!
But it only played the last one, mymacro3!


.... Here is what I have so far:

(1) I have my macros, js files and batch file all located together in "C:\Users\Public\Documents\iMacros\Macros\"

Here are the files I am trying:

My batch files is:

Code: Select all

	@ECHO ON
    REM     ** Be sure to set the correct paths for Firefox **
    ECHO   Set parameters for FireFox to allow scripts to close macros
    cd "C:\Program Files (x86)\Mozilla Firefox\defaults\preferences\"
    COPY all_allowClose.js all.js > junk.txt

    ECHO   Use Load-iMacro web page to launch js file after Firefox is loaded
    cd "C:\Program Files (x86)\Mozilla Firefox\"
    firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro1.js

	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro2.js
	
	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro3.js
    ECHO   Reset parameters for FireFox to disallow scripts to close macros
    cd "C:\Program Files (x86)\Mozilla Firefox\defaults\preferences\"
    COPY all_disallowClose.js all.js > junk.txt

    REM  Back to where we started: Change as needed
    CD C:\
My mymacro1.js looks like this:

Code: Select all

    /*  DemoProcessAndClose.js                                           Version 1.0    */
    /*  Demo macro for Launch-iMacro.html                        May 30, 2008    */


    //  Use try/catch/finally for all main processing


    var report="mymacro1.js \n";
    try
    {
       report += "Navigate to specific site \n";
       iimPlay("mymacro1");
    }
    catch (err)
    {
       report += "**ERROR**: catch processing\n";
       report += err+"\n";
    }
	//alert(report);
    //  CLOSE FIREFOX
    //  under ff 2 you have to manually change C:\Program Files\Mozilla Firefox\greprefs\all.js
    //  set about:config dom.allow_scripts_to_close_windows to true
    setTimeout("window.open('','_parent','');window.close();",2000);
and finally my "mymacro1.iim" looks like this:

Code: Select all

VERSION BUILD=8240212 RECORDER=FX
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO
SET !TIMEOUT 120
TAB CLOSEALLOTHERS
TAB T=1     
URL GOTO=http://demo.imacros.net/Automate/TestForm1
'We use quotation marks for a content with spaces
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:name CONTENT="Suman Tester"
'We manually changed the TAG command from using the postion of a value (e. g. "2") 
'to using its real name, e. g. "Pizza"
TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:food CONTENT=%Pizza
TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:drink CONTENT=%Coke
TAG POS=1 TYPE=INPUT:RADIO FORM=ID:demo ATTR=ID:medium&&VALUE:medium CONTENT=YES
'If you want to select more than one, use a colon (:)
TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:dessert CONTENT=%"ice cream":%"Apple Pie"
TAG POS=1 TYPE=INPUT:RADIO FORM=ID:demo ATTR=NAME:Customer CONTENT=YES
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:demo ATTR=NAME:Reg_code CONTENT=tester
'In a quoted content, we can use \n for a new line, \t for tab and \" for literal quotes
TAG POS=1 TYPE=TEXTAREA FORM=ID:demo ATTR=NAME:Remarks CONTENT="iMacros can fill forms."
TAG POS=1 TYPE=BUTTON:SUBMIT FORM=ID:demo ATTR=TXT:"Click to order now"

... The batch file is starting.
... It loads firefox
... It goes to load the js file, and stops ... doesnt go any further.
Attachments
ScreenShot328.jpg
Screen shot
chivracq
Posts: 8871
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by chivracq » Thu Aug 22, 2013 3:24 am

No-no-no, in my idea, you only want to start 1 .JS File from the Batch (and that's why I called it "RunAllMacros.js") and it is in that .JS File that you'll be calling all .iim Macros successively...

I started the Demo Sef-Test.js from a Batch File (with or without Windows Scheduler) and it works for all the 10 or 12 .iim Macros it contains ...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
wviswildandwonderful
Posts: 21
Joined: Sat Aug 22, 2009 6:35 pm

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by wviswildandwonderful » Thu Aug 22, 2013 4:18 am

chivracq wrote:No-no-no, in my idea, you only want to start 1 .JS File from the Batch (and that's why I called it "RunAllMacros.js") and it is in that .JS File that you'll be calling all .iim Macros successively...

I started the Demo Sef-Test.js from a Batch File (with or without Windows Scheduler) and it works for all the 10 or 12 .iim Macros it contains ...
I'm apparently just NOT getting it! I keep trying but AGAIN... it sticks on the js file..

I have :

BATCH FILE:

Code: Select all

       @ECHO ON
        REM     ** Be sure to set the correct paths for Firefox **
 

        ECHO   Use Load-iMacro web page to launch js file after Firefox is loaded
        cd "C:\Program Files (x86)\Mozilla Firefox\"
        firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=allmymacros.js
  

        REM  Back to where we started: Change as needed
        CD C:\
JS FILE:

Code: Select all

/* This script runs all demo macros and displays the success or failure of each run */
/* Created by: iMacros Team, March 18th, 2008 */

var i, retcode;
var report;
var macrolist = new Array();

/* Standard Demo Macros  */
macrolist.push("Macros/mymacro1.iim");
macrolist.push("Macros/mymacro2.iim");
macrolist.push("Macros/mymacro3.iim");




iimDisplay("Start Self Test");

report  =  "Self-Test Report\n\n";

for (i = 0; i < macrolist.length; i++) {
    iimDisplay("Step "+(i+1)+" of "+macrolist.length + "\nMacro: "+macrolist[i]);
    retcode = iimPlay(macrolist[i]);
    report += macrolist[i];
    if (retcode < 0) {
        report += ": "+iimGetLastError();
    } else {
        report += ": OK";
        /* display the FIRST extracted item in report*/
        s = iimGetLastExtract(1);
        if ( s != "" )  report += ", Extract: "+s;
    }
    report += "\n";
}
iimDisplay("Test complete");

alert ( report );
What am I doing wrong?
davidpoor
Posts: 33
Joined: Fri May 23, 2008 8:45 pm
Contact:

Re: Batch File: Load Firefox, Run Macro(s), Close: STILL WOR

Post by davidpoor » Thu Aug 22, 2013 4:36 pm

I must admit that (a) I have not been using my own code for a couple of years and (b) my old laptop died so I have a totally fresh install of FireFox to play with. Previously, I had only used XP, but my new laptop has Windows 7.

First, I verified that the basic process still works and that the link is good:

I created a test batch file to run an iOpus demo macro (stored as C:\Users\USERNAME\Documents\iMacros\Macros\Demo\Demo\JavascriptDialog.iim)

Code: Select all

     @ECHO OFF
     ECHO   Use Launch-iMacro web page to launch js file after Firefox is loaded
     cd "C:\Program Files (x86)\Mozilla Firefox"
     firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=Demo\JavascriptDialog.iim
     cd C:\Calendar\
It worked as expected - note, however, that the batch file ends before the macro finishes. As soon as Firefox is loaded, control is returned to the batch file so it changes directories and completes.

Then I verified that javascript files also work using the same demo macro. I modified the batch file:

Code: Select all

     @ECHO OFF   
     ECHO   Use Launch-iMacro web page to launch js file after Firefox is loaded
     cd "C:\Program Files (x86)\Mozilla Firefox"
     firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=TestLaunch1.js
     cd C:\Calendar\
And I crearted the test javascript file (stored as C:\Users\USERNAME\Documents\iMacros\Macros\TestLaunch1.js)

Code: Select all

     var ires=iimPlay("Demo/JavascriptDialog.iim");
     alert("iimPlay macro returned "+ires);
Note that is important to retrieve the return code, in this case "var ires=iimPlay(...." If you do not, the javascript will issue the iimPlay and continue. You must explicitly retrieve the return code so that javascript will wait until the macro finishes and the value can be assigned.

SO.... it is working and works with the current version of Firefox (23.0.1), a recent version of iMacros, and Windows 7.
davidpoor
Posts: 33
Joined: Fri May 23, 2008 8:45 pm
Contact:

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by davidpoor » Thu Aug 22, 2013 4:44 pm

For the problem from wviswildandwonderful, it is important to get the return code if you want to wait for the macro to complete. (It may
also be necessary to use the returned value, but I have not tested that possibility).

In your post of Aug 21, you use iimPlay, but you do not get the return code so the js will continue to run. I suspect that it will quickly look through your array and try to play each, thereby clobbering the prior play and only really executing the last - or some other unpredictable behavior.

You can add alert("xxxx") commands throughout your code to help debug the situation and follow your progress, NOT good once the bugs are out, but extremely helpful during development and testing.
wviswildandwonderful
Posts: 21
Joined: Sat Aug 22, 2009 6:35 pm

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by wviswildandwonderful » Fri Aug 23, 2013 3:45 am

Thank you David.

I was able to get it to play using the following:
BATCH FILE:

Code: Select all

  @ECHO OFF   
         ECHO   Use Launch-iMacro web page to launch js file after Firefox is loaded
         cd "C:\Program Files (x86)\Mozilla Firefox"
         firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=testmacro1.js
         cd C:\Calendar\
JS FILE;

Code: Select all

  var ires=iimPlay("testmacro1.iim");
  alert("iimPlay macro returned "+ires);
I still however can not figure out how to get one to play to finish, close move on to the next, etc.

As I did originally like this:

Code: Select all

    @ECHO OFF
    REM     ** Be sure to set the correct paths for Firefox **
    ECHO   Set parameters for FireFox to allow scripts to close macros
    cd "C:\Program Files\Mozilla Firefox\greprefs\"
    COPY all_allowClose.js all.js > junk.txt

    ECHO   Use Load-iMacro web page to launch js file after Firefox is loaded
    cd "C:\Program Files\Mozilla Firefox\"
    firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=login.js
   firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro1.js
	
	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro2.js
	
	firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=mymacro3.js
    ECHO   Reset parameters for FireFox to disallow scripts to close macros
    cd "C:\Program Files\Mozilla Firefox\greprefs\"
    COPY all_disallowClose.js all.js > junk.txt

    REM  Back to where we started: Change as needed
    CD C:\	
and

Code: Select all

    /*  DemoProcessAndClose.js                                           Version 1.0    */
    /*  Demo macro for Launch-iMacro.html                        May 30, 2008    */


    //  Use try/catch/finally for all main processing


    var report="mymacro1.js \n";
    try
    {
       report += "Navigate to specific site \n";
       iimPlay("mymacro1");
    }
    catch (err)
    {
       report += "**ERROR**: catch processing\n";
       report += err+"\n";
    }
	//alert(report);
    //  CLOSE FIREFOX
    //  under ff 2 you have to manually change C:\Program Files\Mozilla Firefox\greprefs\all.js
    //  set about:config dom.allow_scripts_to_close_windows to true
    setTimeout("window.open('','_parent','');window.close();",2000);


..... any ideas?

I tried this:

Code: Select all

         @ECHO OFF   
         ECHO   Use Launch-iMacro web page to launch js file after Firefox is loaded
         cd "C:\Program Files (x86)\Mozilla Firefox"
         firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=testmacro1.js
		 
		 firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=testmacro2.js
		 
		 firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=testmacro3.js
		 
		 firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=testmacro4.js
		 
		 
         cd C:\Calendar\
and it played the first macro (testmacro1)

and then gave this error message at the end
[Exception... "prompt aborted by user" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: resource://gre/components/nsPrompter.js :: openTabPrompt :: line 425" data: no], line: 421 (Error code: 991)
davidpoor
Posts: 33
Joined: Fri May 23, 2008 8:45 pm
Contact:

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by davidpoor » Sun Aug 25, 2013 12:53 am

It is not necessary to start Firefox for each macro. Normally the batch file will complete as soon as Firefox starts so that it might indeed be difficult to start Firefox for each macro... What is likely to happen is that you will send multiple pages to Firefox in rapid succession so that only the LAST is properly executed.

CORRECTION: The above is true if Firefox is already open when you execute your batch file. If ALL Firefox windows are closed before you start, and if you add the window close to each of your js files, you should be able to launch a single batch file that executes Firefox multiple times. I will post an example below.

Try the following script which is a modification of the multiple macros script provided by the iMacros team. In it, you can specify as many macros as you want to run, and then the script will run them in succession and wait for each to complete before starting the next.

I have the js script ending in a single ALERT summarizing the results, but you would remove any alerts if you want this to run unattended.

Note also that it is not necessary to do any special configuration to let the js file close Firefox. Since the js is running in iMacros (not within the displayed page), you can simply re-open the window with an empty page and then close the window.

For this example, I merely picked three of the Demo macros. You should be able to substitute these with your macros.

Code: Select all

     
     //  Run multiple macros: 
     //       modified from script created by: iMacros Team, March 18th, 2008 
     var macrolist = new Array();

     //  set the macros to be executed 
     //  (The following uses standard demo macros, replace with yours!)
     macrolist.push("Demo/JavascriptDialog.iim");
     macrolist.push("Demo/ExtractAndFill.iim");
     macrolist.push("Demo/ImageDownload.iim");

     //  initialization
     var report="";
     var i, retcode;
     report  +=  "Start multiple macros with "+macrolist.length+" macros\n\n";
     //  Optional, but normally a good idea
     retcode=iimPlay("CODE:TAB 1");
     retcode=iimPlay("CODE:TAB CLOSEALLOTHERS");
     //  Loop through the macros
     for (i = 0; i < macrolist.length; i++) 
     {
        retcode = iimPlay(macrolist[i]);
        report += "Step "+(i+1)+", "+macrolist[i];
        if (retcode < 0) 
        {
           report += ": "+iimGetLastError()+"\n";
        } else 
        {
           report += ": OK\n";
        }
     }
     report += "Finished after "+macrolist.length+" macros.";
     alert ( report );

     //  Close the window
     window.open('','_parent','');
     window.close();

Then use the launch iMacro process with the above js file. (I called it TestLaunch2.js)

David
Last edited by davidpoor on Sun Aug 25, 2013 11:41 am, edited 1 time in total.
chivracq
Posts: 8871
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by chivracq » Sun Aug 25, 2013 2:10 am

It worked as expected - note, however, that the batch file ends before the macro finishes. As soon as Firefox is loaded, control is returned to the batch file so it changes directories and completes.
This is why I meant that only ONE Macro (.iim or .js) can be launched from a Batch File (because that's indeed the behaviour that I have been observing since I've been using Macros launched through a Batch File (on Win7 and Win8)), but I could still test on WinXP to see if the DOS Interpreter has changed...

And thus, WV, if you want to run several Macros in a row, you need either to add some generous "timeout 300+" between your Macros in the Batch File to allow them to run and finish, or you need to launch them all from ONE .js Macro by concatenating all your .js Macros or by using the PUSH method I mentioned where I think you made a Path Error with "macrolist.push("Macros/mymacro1.iim");", => should be "macrolist.push("mymacro1.iim");".

EDIT: And I see that davidpoor has replied as well in the meantime, using that very same PUSH method...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
davidpoor
Posts: 33
Joined: Fri May 23, 2008 8:45 pm
Contact:

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by davidpoor » Sun Aug 25, 2013 11:48 am

For the correction above:

If ALL Firefox windows are closed before you start, and if you add the window close to each of your js files, you should be able to launch a single batch file that executes Firefox multiple times. (I had forgotten this behavior.)

This batch file runs the same js twice. The batch file waits for the first completion of Firefox before continuing to the second...

Code: Select all

@ECHO OFF
ECHO   Use Launch-iMacro web page to launch js file after Firefox is loaded
cd "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=TestLaunch2.js
ECHO   And again... 
firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=TestLaunch2.js
cd C:\
ECHO: DONE!
Although it is shown above, here is the same TestLaunch2.js:

Code: Select all

     
     //  set the macros to be executed (using standard demo macros)
     var macrolist = new Array();
     macrolist.push("Demo/JavascriptDialog.iim");
     macrolist.push("Demo/ExtractAndFill.iim");
     macrolist.push("Demo/ImageDownload.iim");
     report  +=  "Start multiple macros with "+macrolist.length+" macros\n\n";
     //  Optional, but normally a good idea
     retcode=iimPlay("CODE:TAB 1");
     retcode=iimPlay("CODE:TAB CLOSEALLOTHERS");
     //  Loop through the macros
     for (i = 0; i < macrolist.length; i++) 
     {
        retcode = iimPlay(macrolist[i]);
        report += "Step "+(i+1)+", "+macrolist[i];
        if (retcode < 0) 
        {
           report += ": "+iimGetLastError()+"\n";
        } else 
        {
           report += ": OK\n";
        }
     }
     report += "Finished after "+macrolist.length+" macros.";
     alert ( report );
     
     window.open('','_parent','');
     window.close();
wviswildandwonderful
Posts: 21
Joined: Sat Aug 22, 2009 6:35 pm

Re: Batch File: Load Firefox, Run Macro(s), Close

Post by wviswildandwonderful » Mon Aug 26, 2013 4:54 pm

Thanks! I will try these.
Post Reply