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.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

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

by davidpoor on Sun Jun 01, 2008 9:11 am

SUMMARY: Shows how to use a batch file and Launch-iMacros.html to enable autonomous batch processing to
    (a) launch Firefox
    (b) run one or more macros, and
    (c) close Firefox
I was unable to totally automate a daily process because I need to execute a series of macros and I could not figure out how to open Firefox, run the macros, and then close Firefox to continue with the batch.

Here is my solution. It does require several steps:
    Set Firefox to allow a script to close the main Firefox window
    Launch Firefox with Launch-iMacros.html web page which will wait for Firefox to load and then continue with the iOpus http://run.imacros.net/ processing
    Use javascript to close Firefox
    Set Firefox back to normal.

STEP 1: Allow a script to close the main Firefox window
Use an editor (Notepad will do) to modify your Firefox setting. The file "all.js" can be found off of the directory
in which you installed Firefox then subdirectory "greprefs", e.g.: C:\Program Files\Mozilla\Firefox\greprefs\all.js

Find the line that has the following and change "false" to "true".
pref("dom.allow_scripts_to_close_windows", false);

You can save the file to make the change permanent, however, I recommend having two copies of "all.js" I made a copy of the original file and renamed it to "all_disallowClose.js" and put the change in a second copy called "all_allowClose.js".

STEP 2: Launch Firefox
Since Firefox should not be running, you can not merely use [path]firefox.exe http://run.imacros.net/?m=xxxx.iis.
The solution is to open Firefox to utilize Launch-iMacros.html to (a) wait until Firefox is open and then (b) navigate to http://run.imacros.net/?m=xxxx.iis.

The needed page Launch-iMacros.html is attached as file to this post and can also be referenced from a site I have provided. Just set the correct path for Firefox, put in the name of your macro (with the .iis or .js extensions!) and save as a batch file.
Code: Select all
[path]firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=xxxx.iis

    SHARED MACRO SECURITY ISSUE: iOpus correctly recognizes possible security risks associated with running macros called from a remote server. You will need to authorize the use of the remote site. Set as permanently trusted if you plan to have automated batches running unattended.
The complete code list is also shown at the end of this post.

STEP 3: Close Firefox
This can be done with the simple code
Code: Select all
window.open('','_parent','');
window.close();",2000);

Note, however, that this requires using javascript. The easiest way is to change your call to Launch-iMacros.html to reference a js file and then have the js file "play" your macro.

A simple example would be to create the following "runMyMacro.js" file to accompany your "myMacro.iis".
runMyMacro.js
Code: Select all
iimPlay("myMacro");
window.open('','_parent','');
window.close();

Then you would launch Firefox with the following batch file.
Code: Select all
[path]firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=runMyMacro.js


A DEMO:

This demo merely runs a sandard iMacro Demo macro, waits a couple of seconds, and then closes Firefox.

Copy the attched file "DemoProcessAndClose.js into the directory with your iMacros iim files, or use past the following into your iMacro editor and save it as "DemoProcessAndClose.js".
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="DemoProcessAndClose.js \n";
try
{
   report += "Navigate to specific site \n";
   iimPlay("Demo-Filter");
}
catch (err)
{
   report += "**ERROR**: catch processing\n";
   report += err+"\n";
}

//  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);


Now copy the attached bacth file "DemoLaunchProcessAndClose.bat" to a directory of your choice (or on your desktop). Alternatively, you can copy and paste from the following:

BEFORE YOU START!! Check your Firefox directory and change accordingly before you execute the batch file.
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=DemoProcessAndClose.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:\


Now, run the batch file. I generally like to use a Command Prompt window so I can see what goes wrong!

LINUX? OSX? Let me know if this works for other operating systems. I am using XP.

Full listing of Launch-iMacro.html: Updated 03/01/2009: ddsp
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Launch-iMacro: Javascript to launch iMacro in Firefox</title>
    <meta content="General" name="rating">
    <meta content="ALL"     name="ROBOTS">

    <script type="text/javascript">
     
    //  "Launch-iMacro.html" must be run from a server (using http:// or https://)
    //  You may use the version at www.MBILtd.net/iMacros/Launch-iMacro.html?m=[macroorjava]
   
    /*  Changelog...
        Version    Date           Comment
        1.0        05/30/2009     Initial release
        1.001      03/01/2009     Fix missing close on span, missing div close &lt;/div&gt;
                                  Enhanced error message
                                  Execute launchMacro only if passed macro found
                                  Add Run: documentation in launchMacro
        ---------------------------------------------------------------  */
           
    var passedMacro = "";
       
    function showParameters()
    {
      var thisURI = ""+window.location;     // converts window.location to a string
      if (thisURI.indexOf("?m=") > 0) passedMacro = thisURI.substr(thisURI.indexOf("?m=")+3);
      if (passedMacro.length > 0)
      {
         parameters.innerHTML = "Macro: "+passedMacro;
         setTimeout('launchMacro(passedMacro)',1000);
      }
      else
      {
          parameters.innerHTML = "missing macro parameter<br><br>"+
             "use ...\Launch-iMacro.html?m=[macroparameter] where<br>"+
             "[macroparameter] is a macro filename including .iim extension<br>"+
           "or a javascript filename including .js extension";            
      }   
    }   

    function launchMacro(thisMacro)
    {
       if (passedMacro.length > 0)
       {
           parameters.innerHTML += "<br><br>Run: http://run.imacros.net/?m="+thisMacro;
           document.location = "http://run.imacros.net/?m="+thisMacro; 
       }
    }
    </script>

</head>

<body onLoad="showParameters();" >
   <div align="center">
      <h1>Launch-iMacro.html</h1><br>
      <hr>
      Version 1.001<br>
      March 1, 2009<br>
      David Poor<br>
      <hr>
      <span id="parameters"></span>
   </div>
</body>
</html>

Comments and suggestions appreciated!
Last edited by davidpoor on Sun Mar 01, 2009 5:31 pm, edited 2 times in total.
davidpoor
 
Posts: 33
Joined: Fri May 23, 2008 1:45 pm

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

by Tech Support on Tue Jun 03, 2008 8:44 am

Thanks for this very useful posting! I added a link to it from our iMacros for Firefox Wiki page:
http://wiki.imacros.net/iMacros_for_Fir ... ne_Support

Ann
User avatar
Tech Support
 
Posts: 5003
Joined: Tue Sep 20, 2005 12:25 pm

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

by bravo on Sun Aug 24, 2008 2:55 pm

Following fragment is not complete and gives error:
Code: Select all
    function launchMacro(thisMacro)
    {
       if (passedMacro.length > 0)
           document.location = "
    }


What follows after
Code: Select all
document.location = "
?
bravo
 
Posts: 1
Joined: Mon Aug 04, 2008 9:37 am

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

by davidpoor on Mon Aug 25, 2008 6:54 am

Thank you for catching this problem. The entry should have been:
Code: Select all
       if (passedMacro.length > 0)
           document.location = "http://run.imacros.net/?m="+thisMacro;

Fortunately the entire line is present on the site, but, obviously, the lack of the link would cause any other installation to fail. I do not know what happened that caused the link to be lost, but I have corrected it in the original post.

David
davidpoor
 
Posts: 33
Joined: Fri May 23, 2008 1:45 pm

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

by PsychedeliX on Sat Feb 28, 2009 7:38 am

Hi,

I have a problem with the "Launch iMacros.html" - On some web servers this works, on others not.

When I use http://www.mbiltd.net/iMacros/Launch-iMacro.html - it works perfect, even when I start the .html on my HomePC in HttpFileServer (http://www.rejetto.com/hfs/) My Macro start without any problems.

But it doesn't work on two web servers i've tested, what is the reason? On these two servers the macro will displayed normal, but it wont start ...

Code: Select all
 Launch iMacro.html

Version 1.0
May 30, 2008
David Poor
Macro: test.js


I've also tried to allow the server URL's before calling the macro, but unfortunately no success.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hi,

ich habe ein Problem mit der "Launch-iMacros.html" - Auf einigen Webservern funktioniert diese, auf anderen nicht.

Benutze ich http://www.mbiltd.net/iMacros/Launch-iMacro.html - funktioniert diese einwandfrei, auch wenn ich die .html auf meinem HomePC im HttpFileServer starte (http://www.rejetto.com/hfs/) startet mein Macro ohne Probleme.

Das ganze funktioniert jedoch nicht auf zwei getesteten Webservern, woran kann das liegen? Auf diesen zwei Servern wird das Macro, welches ich starten möchte angezeigt, startet jedoch nicht ...

Code: Select all
Launch-iMacro.html

Version 1.0
May 30, 2008
David Poor
Macro: test.js


Ich habe auch schon versucht, die URL's vor dem aufruf im Imacros Addon freizugeben, leider kein Erfolg.
PsychedeliX
 
Posts: 60
Joined: Sat Feb 28, 2009 7:16 am

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

by davidpoor on Sat Feb 28, 2009 9:53 am

As all of the processing is within JavaScript, I do not see how different servers would impact the functioning of the page.

The process will not work without JavaScript being enabled. However, since your are seeing "test.js" in the parameter list, it is obvious that JavaScript is working on the page.

So, JavaScript is working for you, but your "test.js" is apparently not being executed. I would suggest that you check a couple of items:

* Check that the page returned from the server exactly as expected (view source)
* Check that you are executing the launchMacro function. Perhaps add an alert("In launchMacro, passedMacro=>"+passedMacro+"<.") at the start of the function.
* Check the location of your "test.js". (I believe that it must reside on the server in the same folder as the Launch-iMacro.html file.)
* Turn on the ErrorConsole to be sure that there is no javascript error that is stopping execution.
* Check to see that the "test.js" source is being loaded and executed by adding an alert to it.
davidpoor
 
Posts: 33
Joined: Fri May 23, 2008 1:45 pm

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

by PsychedeliX on Sat Feb 28, 2009 11:20 am

i can call every macro i want, regardless of whether it exists or not - the script accept it, after that nothing happens

at your server this message comes up as normal

Code: Select all
iMacros Run command: Macro macrodontexist not found


here is a example

http://www.onlytostart.homepage.t-onlin ... odontexist

the sourcecode seems to be ok

this is what the error console shows:

my server

Code: Select all
Warnung: Ein Element wurde im globalen Geltungsbereich per ID/Name referenziert. Verwenden Sie den W3C-Standard document.getElementById() stattdessen.
Quelldatei: http://www.onlytostart.homepage.t-online.de/Launch-iMacro.html?m=test.js
Zeile: 22

Fehler: uncaught exception: [Exception... ""  nsresult: "0x805e000a (<unknown>)"  location: "JS frame :: http://www.onlytostart.homepage.t-online.de/Launch-iMacro.html?m=test.js :: launchMacro :: line 35"  data: no]


your server

Code: Select all
Warnung: Ein Element wurde im globalen Geltungsbereich per ID/Name referenziert. Verwenden Sie den W3C-Standard document.getElementById() stattdessen.
Quelldatei: http://www.mbiltd.net/iMacros/Launch-iMacro.html?m=test.js
Zeile: 23

Fehler: uncaught exception: [Exception... ""  nsresult: "0x805e000a (<unknown>)"  location: "JS frame :: http://www.mbiltd.net/iMacros/Launch-iMacro.html?m=test.js :: launchMacro :: line 36"  data: no]


this can't be the reason i think, because the errors are the same at your and mine server
PsychedeliX
 
Posts: 60
Joined: Sat Feb 28, 2009 7:16 am

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

by davidpoor on Sun Mar 01, 2009 5:45 pm

Thank you PsychedeliX.

First, I apologize: of course the .iim or .js must be in the iMacros directory on the client.

Secondly, JavaScript can not tell whether a file exists or not. If the requested macro does not exist, you should get an error from the iMacro run process. The program can only determine whether you have left out the ?m= or the macro name.

I have made a few enhancements/updates to the main file, but nothing that is of real substance. (I corrected two small HTML errors that prevented the page from validating; I added a check to for a zero length macro name; and I enhanced the displayed messages including showing the exact URL for the page transfer.

The main issue is why is the system not working for you. I am also getting the same error on my demo server and my production server: two different ISPs. In both cases, I get the error, but the page still works properly!

Try loading the newest version (1.001 above) and see if it works, albeit with the error message. NOTE: Be sure to add the .iim or .js suffix to your macro.

In the interim, I will think about alternative ways to change the page. The error may have to do with changing domains: I really do not know.

David
davidpoor
 
Posts: 33
Joined: Fri May 23, 2008 1:45 pm

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

by Netronwizard on Wed Mar 25, 2009 10:06 pm

Hi David,

I have a couple of questions. I'm trying to use your files and modify them so I can use them to automate my macro. The problem with modifying them is that I can't seem to get the files to use my macro. I'm also new to the whole macro world and most likely over looking some small thing. If I give you the file names can you help me build the files I need to auto execute my macro? :oops:

Oh, is there also a way to make it a time sequenced batch file?

Thanks, Netronwizard
Netronwizard
 
Posts: 4
Joined: Tue Mar 24, 2009 11:43 pm

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

by ændrük on Wed May 20, 2009 11:52 am

I'm stumped. Any thoughts on what might be causing this message in the Firefox error console?
Code: Select all
Error: uncaught exception: [Exception... ""  nsresult: "0x805e000a (<unknown>)"  location: "JS frame :: file:///home/ak/iMacros/Launch-iMacros.html?m=WWU%2FWWUwireless%20Bluesocket.iim :: launchMacro :: line 48"  data: no]

The line in Launch-iMacros.html it's breaking on is
Code: Select all
document.location = "http://run.imacros.net/?m="+thisMacro;

The page does successfully write
Code: Select all
Run: http://run.imacros.net/?m=WWU%2FWWUwireless%20Bluesocket.iim

to the document but errors out before actually navigating to the URL. If I copy and paste the URL into the address bar the iMacro is run without any problems.

EDIT: Wow, sorry for that. I didn't realize this was the same message as the one posted earlier.

EDIT: More information:
  • Running javascript:document.location="http://run.imacros.net/?m=WWU%2FWWUwireless%20Bluesocket.iim" from the address bar works as it should only when I am currently at a website on the internet; if I am currently at any file on my computer the above error message is logged.
  • If I disable the iMacros addon (none of my other addons seem to have any effect), the redirect works anywhere without error. (But, of course, the macro is not run in the next step.)

    I think the "fix" for this situation will have to involve changes to iMacro itself to allow whitelisting of local URLs.
ændrük
 
Posts: 1
Joined: Wed May 20, 2009 11:43 am

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

by davidpoor on Wed May 20, 2009 12:51 pm

I am not surprised as processing local files uses a special protocol (e.g. file:///C:/...) and a web page processing uses http or https (e.g. http://www....).

If I need to run locally (such as a development), I use a server instance installed on my computer (http://localhost...) and reference pages relative to the root of the "server" rather than based on the computer directory tree.

Also, I often set up my macros to start with an innocuous page (e.g. www.google.com) and then go to the first page of the web site on which I actually will do processing as some sites keep session variables or cookies to show that you are already there and this ensures a clean entrance.

ddsp
davidpoor
 
Posts: 33
Joined: Fri May 23, 2008 1:45 pm

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

by MickeyKnox on Sun May 30, 2010 9:50 pm

I had make a Script based on your "article" davidpoor.
Here is the URL: http://knox-it.blogspot.com/2010/05/batch-automatizacion-para-ejecucion-de.html in case you wanna take a look.

Saludos desde Argentina!

Mickey Knox - http://knox-it.blogspot.com/
MickeyKnox
 
Posts: 1
Joined: Sun May 30, 2010 9:41 pm

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

by BilboBaggins on Sat Dec 15, 2012 8:17 am

TAB CLOSEALLOTHERS
*closes all but one tab
TAB CLOSE
*Closes the last tab, along with Firefox

Works for me.
BilboBaggins
 
Posts: 1
Joined: Sat Dec 15, 2012 8:05 am

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

by bobis on Sun Dec 16, 2012 5:56 pm

BilboBaggins wrote:TAB CLOSEALLOTHERS
*closes all but one tab
TAB CLOSE
*Closes the last tab, along with Firefox

Works for me.


This solution bad because it will very often leave firefox process stuck in the memory, so you won't be able to restart Firefox - you'll have to stop process from task manager first.
Get Best iMacros scripts at http://imacrosbot.com/
User avatar
bobis
 
Posts: 364
Joined: Sat Sep 11, 2010 8:34 am

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

by jadmanx on Mon Feb 25, 2013 7:34 pm

can not found C:\Program Files\Mozilla\Firefox\greprefs\all.js

now in C:\Users\Florian\AppData\Roaming\Mozilla\Firefox\Profiles\*\all.js

but downt worke to change ..

witht about:config you can change pref("dom.allow_scripts_to_close_windows", false); to pref("dom.allow_scripts_to_close_windows", true);

but firefox downt exit ...

help!!!!!!!!!!!!!!!!
jadmanx
 
Posts: 15
Joined: Thu Apr 19, 2007 4:27 pm

Next

Return to iMacros for Firefox

Who is online

Users browsing this forum: Google [Bot] and 9 guests

-->