- (a) launch Firefox
(b) run one or more macros, and
(c) close Firefox
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.
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".
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".pref("dom.allow_scripts_to_close_windows", false);
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.
STEP 3: Close Firefox
This can be done with the simple code
Code: Select all
window.open('','_parent','');
window.close();",2000);
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();
Code: Select all
[path]firefox.exe http://www.MBILtd.net/iMacros/Launch-iMacro.html?m=runMyMacro.js
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);
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 </div>
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>