SOF: "iMacros Javascript Macro execute commands after closed Browser"

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
Post Reply
chivracq
Posts: 8315
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

SOF: "iMacros Javascript Macro execute commands after closed Browser"

Post by chivracq » Mon Mar 11, 2019 2:58 am

Interesting Thread on SOF from 3 days ago, not really for the Content (I honestly don't really understand the Qt if any), but the Script is using some very-very "exotic" Commands that have been deprecated for more than 10 years, making it a complete "Gem" and a real "Collector Item" for the Forum..., youpidoo...! :D

For a few of those Commands I had never seen them before, but yep, they are still documented in the Wiki, and I guess they probably still work in v8.9.7.
User on SOF didn't mention their FCI even after I asked them, but OK, here is the complete Thread... Enjoy...! :roll:

Original Thread on SOF:
- Imacros javascript macro execute commands after closed browser
User on SOF = camomillo

I have an imacros javascript macro that use some if to execute the commands.

This imacros javascript close in automatically firefox if the are some conditions but execute other commands after firefox is closed.

This imacros javascript grab current ip on internet and save it in variable.

Check if the ip grabbed is #EANF# (not extracted) and close firefox.

Compare with a loop the current ip with a list of ip saved in csv and if current ip is already used close firefox.

Update the loop number.

Update some firefox settings.

Run an iim macro.

Save info in csv.

Open a batch file.

With a loop check the current ip to check the connection internet is up.

This imacros javascript have a problem, after closed firefox because an if statement is true run bat file but the batch file will be run only if the if statement will not found.

Why after the firefox will be closed run start.bat ?

The if were inserted to interrupt the execution of the script and to close firefox but note that the bat file is also loaded.

I need to run start.bat only when firefox not will be closed with iimPlayCode ("TAB CLOSE") command.

This is the code

Code: Select all

////////////////////////////////////////////////////////
/////////////////////// Variables //////////////////////
////////////////////////////////////////////////////////

var jsNewLine = "\n"
var Loops = 500

////////////////////////////////////////////////////////
///////// Clear Cookies And Cache With Imacros /////////
////////////////////////////////////////////////////////

iimPlayCode ("CLEAR")

////////////////////////////////////////////////////////
//////////////////// Ip Current Save ///////////////////
////////////////////////////////////////////////////////

iimPlayCode ("TAB OPEN")
iimPlayCode ("TAB T=2")
iimPlayCode ("URL GOTO=https://ident.me/")
iimPlayCode ("WAIT SECONDS=10")
iimPlayCode ("TAG POS=1 TYPE=PRE ATTR=* EXTRACT=TXT")

////////////////////////////////////////////////////////
////////////// Save Ip Current In Variable /////////////
////////////////////////////////////////////////////////

IpCurrent = iimGetLastExtract(1);

////////////////////////////////////////////////////////
/////////////////////// Close Tab //////////////////////
////////////////////////////////////////////////////////

iimPlayCode ("TAB CLOSE")

////////////////////////////////////////////////////////
//////////// Ip Current #EANF# Close Browser ///////////
////////////////////////////////////////////////////////

if (IpCurrent == "#EANF#")

{
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("PAUSE")
}

////////////////////////////////////////////////////////
///////////////////////// Loop /////////////////////////
////////////////////////////////////////////////////////

for (i = 0; i < Loops; i ++ )

{

////////////////////////////////////////////////////////
////////////////////// Macro Code //////////////////////
////////////////////////////////////////////////////////

code = "";
code += "CODE:" + jsNewLine
code += "SET !ERRORIGNORE YES" + jsNewLine
code += "SET !LOADCHECK YES" + jsNewLine
code += "SET !REPLAYSPEED FAST" + jsNewLine
code += "SET !POINTER YES" + jsNewLine
code += "SET !TIMEOUT 30" + jsNewLine
code += "SET !TIMEOUT_TAG 0" + jsNewLine
code += "SET !EXTRACT_TEST_POPUP NO" + jsNewLine

code += "SET !DATASOURCE F:\\ip_addresses_used.csv" + jsNewLine
code += "SET !DATASOURCE_COLUMNS 2" + jsNewLine
code += "SET !DATASOURCE_LINE " + i + jsNewLine

code += "ADD !EXTRACT {{!COL1}}" + jsNewLine

iimPlay(code);

////////////////////////////////////////////////////////
/////////////// Save Ip Used In Variable ///////////////
////////////////////////////////////////////////////////

IpUsed = iimGetLastExtract(1);

////////////////////////////////////////////////////////
///////////////////// Display Loop /////////////////////
////////////////////////////////////////////////////////

iimDisplay("Completed Loop " + i)

////////////////////////////////////////////////////////
/// Compare Ip Current (Extracted) With Ip Used (Csv) //
////////////////////////////////////////////////////////

if (IpCurrent == IpUsed)

{
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("PAUSE")
}

}

////////////////////////////////////////////////////////
////////////////// Settings On Firefox /////////////////
////////////////////////////////////////////////////////

prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref("pdfjs.disabled", true);  // Disable Pdf Js
prefs.setBoolPref("webgl.disabled", true);  // Disable WebGL
prefs.setBoolPref("webgl.enable-webgl2", false);  // Disable WebGL2
prefs.setBoolPref("media.peerconnection.enabled", false); // Disable WebRTC
prefs.setBoolPref("xpinstall.signatures.required", false); // Disable Xpi Addons Signature (For Ras)
prefs.setCharPref("browser.startup.homepage", "about:memory");  // Browser Startup Homepage
prefs.setIntPref("browser.display.use_document_fonts", 0);  // Disable Numbers Of Fonts
prefs.setIntPref("browser.sessionhistory.max_entries", 2); // Disable Tab History

////////////////////////////////////////////////////////
/////////////////////// Run Macro //////////////////////
////////////////////////////////////////////////////////

iimPlay ("mymacro.iim")

////////////////////////////////////////////////////////
///////////////////// Save Ip Used /////////////////////
////////////////////////////////////////////////////////

IpNote = "VM-Views-1";
iimSet("IpCurrent", IpCurrent);  // Need It To Store Variable
iimSet("IpNote", IpNote);  // Need It To Store Variable
iimPlayCode ("SET !EXTRACT {{IpCurrent}}\n ADD !EXTRACT {{!NOW:dd-mm-yyyy_hh-nn}}\n ADD !EXTRACT {{IpNote}}\n SAVEAS TYPE=EXTRACT FOLDER=F:\\ FILE=ip_addresses_used.csv");

////////////////////////////////////////////////////////
///////////////////// Run Bat File /////////////////////
////////////////////////////////////////////////////////

var file = Components.classes["@mozilla.org/file/local;1"]
                     .createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("D:\\Programmi Installati\\Macro\\bat\\start.bat");
file.launch();

////////////////////////////////////////////////////////
////////////// Checking Connection Status //////////////
////////////////////////////////////////////////////////

////////////////////////////////////////////////////////
/////////////////////// Variables //////////////////////
////////////////////////////////////////////////////////

var Checks = 100

////////////////////////////////////////////////////////
///////////////////////// Loop /////////////////////////
////////////////////////////////////////////////////////

for (c = 0; c < Checks; c ++ )

{

////////////////////////////////////////////////////////
//////////////////// Ip Current Save ///////////////////
////////////////////////////////////////////////////////

iimPlayCode ("TAB OPEN")
iimPlayCode ("TAB T=2")
iimPlayCode ("URL GOTO=https://ident.me/")
iimPlayCode ("WAIT SECONDS=10")
iimPlayCode ("TAG POS=1 TYPE=PRE ATTR=* EXTRACT=TXT")

////////////////////////////////////////////////////////
////////////// Save Ip Current In Variable /////////////
////////////////////////////////////////////////////////

IpCurrent = iimGetLastExtract(1);

////////////////////////////////////////////////////////
/////////////////////// Close Tab //////////////////////
////////////////////////////////////////////////////////

iimPlayCode ("TAB CLOSE")
iimPlayCode ("WAIT SECONDS=600")

////////////////////////////////////////////////////////
//////////// Ip Current #EANF# Close Browser ///////////
////////////////////////////////////////////////////////

if (IpCurrent == "#EANF#")

{
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("TAB CLOSE")
iimPlayCode ("PAUSE")
}

}
+ Quotes of Comments (on SOF also):
'FCIM' as a start, read my Sig (hum, maybe on the iMacros Forum)... - But your Script is a complete "Joke", sorry...!, this is 2019 but it is full of Commands that have been deprecated for at least 10 years...!
(And for a few, that I had never heard of, ah-ah...!)
- Open a parallel Thread on the iMacros Forum, nbd on SOF will be able to read your Script...
I will quote your Thread anyway after 2 or 3 days as your Thread is really a "Collector Item", ah-ah...!, quite interesting for the iMacros Forum though..., miam-miam...!
– chivracq 2 days ago

Hum OK, and I read your "Scenario Description", but it doesn't really make sense to me to be honest, and I don't even understand your only Qt: "Why after the firefox will be closed run start.bat ?", which again doesn't make sense, or even just grammatically...
– chivracq 2 days ago

Hi i need to stop script execution after if (IpCurrent == "#EANF#") or if (IpCurrent == IpUsed) in these case i need to stop the execution of script and close firefox and do not continue the script. actually the script continue and execute the bat file.
– camomillo 2 days ago

Well, "stop script execution" is not complicated, that's automatic and default behaviour with '#EANF#' if you don't use '!ERRORIGNORE', or with 'EVAL()' + 'MacroError()' and also with 'EVENT:FAIL_IF_FOUND'.
- And to close FF, you have a Thread on the iMacros Forum with 5 or 6 different ways to do so, and most of those 5 or 6 can be called conditionally, especially if using a '.js' Script. – chivracq
Be honest...!, who knew about '!LOADCHECK' and '!POINTER'...!?, ah-ah...!? :D :twisted: :D

And yep, '!TIMEOUT' and '!TIMEOUT_TAG' do still work (in v8.8.2 + v8.9.7 for FF), I also still have a few in some of my "older" Scripts from 10 or 8 years ago that I didn't bother to update (and still use)... 8)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Tom, Tech Support
Posts: 3481
Joined: Mon May 31, 2010 4:59 pm

Re: SOF: "iMacros Javascript Macro execute commands after closed Browser"

Post by Tom, Tech Support » Wed Apr 17, 2019 1:48 pm

chivracq wrote:
Mon Mar 11, 2019 2:58 am
Be honest...!, who knew about '!LOADCHECK' and '!POINTER'...!?, ah-ah...!? :D :twisted: :D
I was aware of !POINTER, and its replacement !MARKOBJECT, but this is the first time I've heard of !LOADCHECK!
Regards,

Tom, iMacros Support
chivracq
Posts: 8315
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SOF: "iMacros Javascript Macro execute commands after closed Browser"

Post by chivracq » Wed Apr 17, 2019 2:06 pm

Tom, Tech Support wrote:
Wed Apr 17, 2019 1:48 pm
chivracq wrote:
Mon Mar 11, 2019 2:58 am
Be honest...!, who knew about '!LOADCHECK' and '!POINTER'...!?, ah-ah...!? :D :twisted: :D
I was aware of !POINTER, and its replacement !MARKOBJECT, but this is the first time I've heard of !LOADCHECK!
Ah OK, thanks for the "Feedback", ah-ah...! 8)

Funnily enough, we had nearly at the same time, another User opening a Thread with again the same and a few other "anticoexotic" Commands like '!ERRORMACRO' for example that I didn't know either. (User using iMB v4, ah-ah...!) :wink:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Tom, Tech Support
Posts: 3481
Joined: Mon May 31, 2010 4:59 pm

Re: SOF: "iMacros Javascript Macro execute commands after closed Browser"

Post by Tom, Tech Support » Wed Apr 17, 2019 2:55 pm

Yes, I read that one today too. I was not aware of !ERRORMACRO either!
Regards,

Tom, iMacros Support
chivracq
Posts: 8315
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SOF: "iMacros Javascript Macro execute commands after closed Browser"

Post by chivracq » Wed Apr 17, 2019 4:08 pm

Tom, Tech Support wrote:
Wed Apr 17, 2019 2:55 pm
Yes, I read that one today too. I was not aware of !ERRORMACRO either!
Pretty "interesting" Command btw, this '!ERRORMACRO' Command... "Pity" it was/is not backward-supported anymore at some point (I had checked in v8.8.2 and v8.9.7), it could/might have offered a Workaround for the 'URL GOTO=imacros://run/?m=' Syntax which is not supported anymore in v10.0.2 for FF. :cry:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Post Reply