LOOP in JavaScript

Discussions and Tech Support specific to the iMacros Firefox add-on.
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
mzuske
Posts: 24
Joined: Fri Aug 29, 2008 3:07 pm

LOOP in JavaScript

Post by mzuske » Fri Jan 08, 2010 1:40 pm

Hi....
I have a problem
I'm running a JavaScript file to run one macro after the other one, something like this:
//test.js
iimPlay("macro1",60)
iimPlay("macro2",60)
iimPlay("macro3",60)
....

But now i have marco1 with a loop function and i need to loop it for example 100 times and after that run the next macro....
How do i set the loop option here in the javascript?!

thanks
Hannes, Tech Support

Re: LOOP in JavaScript

Post by Hannes, Tech Support » Mon Jan 11, 2010 11:03 am

Do the looping in the JS code itself, like in this VBS example: http://wiki.imacros.net/VBS_looping
mzuske
Posts: 24
Joined: Fri Aug 29, 2008 3:07 pm

Re: LOOP in JavaScript

Post by mzuske » Mon Jan 11, 2010 6:22 pm

thanka - i copied the "samplecode" in my JS-Macro - but it doesn´t start - it says "syntax error in line 1". Does this work with the firefoxplugin?!
ABooth
Posts: 223
Joined: Mon Aug 10, 2009 4:25 pm

Re: LOOP in JavaScript

Post by ABooth » Mon Jan 11, 2010 6:52 pm

Code: Select all

const iterations = 100;

for( var i=0; i<iterations; i++)
    iimPlay("macro1", 60);

iimPlay("macro2", 60);
iimPlay("macro3", 60);
iMacros for Firefox supports JavaScript Macros (Scripting)
JavaScript supports Java via LiveConnect

Therefore: You can write powerful macros with iMacros for Firefox. Have a look at this one

Post feature requests here. Maybe one day, they'll pin it?
mzuske
Posts: 24
Joined: Fri Aug 29, 2008 3:07 pm

Re: LOOP in JavaScript

Post by mzuske » Wed Jan 13, 2010 9:46 am

fine thanks!
it works!!!

the only problem is now, that the marco i try to run in loop only runs the CSV first line in every run...?!
This is the macro:

VERSION BUILD=6240709 RECORDER=FX
TAB T=1
SET !EXTRACT_TEST_POPUP NO
SET !REPLAYSPEED FAST
SET !ERRORIGNORE YES
SET !DATASOURCE DATAS.csv
SET !DATASOURCE_LINE {{!LOOP}}
SET !DATASOURCE_COLUMNS 1
SET !DIALOGMANAGER NO
URL GOTO={{!COL1}}
ABooth
Posts: 223
Joined: Mon Aug 10, 2009 4:25 pm

Re: LOOP in JavaScript

Post by ABooth » Wed Jan 13, 2010 4:01 pm

That's because you are running it once only, every time, so {{!LOOP} is always 1

Modify the JavaScript macro as below

Code: Select all

const iterations = 100;

for( var i=1; i<=iterations; i++)
{
	iimSet("iteration", i);
	iimPlay("macro1", 60);
}

iimPlay("macro2", 60);
iimPlay("macro3", 60);
Change your iMacro as below

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1
SET !EXTRACT_TEST_POPUP NO
SET !REPLAYSPEED FAST
SET !ERRORIGNORE YES
SET !DATASOURCE DATAS.csv
SET !DATASOURCE_LINE {{iteration}}
SET !DATASOURCE_COLUMNS 1
SET !DIALOGMANAGER NO
URL GOTO={{!COL1}}
iMacros for Firefox supports JavaScript Macros (Scripting)
JavaScript supports Java via LiveConnect

Therefore: You can write powerful macros with iMacros for Firefox. Have a look at this one

Post feature requests here. Maybe one day, they'll pin it?
mzuske
Posts: 24
Joined: Fri Aug 29, 2008 3:07 pm

Re: LOOP in JavaScript

Post by mzuske » Thu Jan 14, 2010 10:59 am

it works - thanks!
mzuske
Posts: 24
Joined: Fri Aug 29, 2008 3:07 pm

Re: LOOP in JavaScript

Post by mzuske » Wed Feb 17, 2010 11:43 am

thanks for helping me now i have a nother little JS problem with this script:

const iterations = 100;

for( var i=1; i<=iterations; i++)
{
iimSet("iteration", i);
iimPlay("macro1", 60);
}

iimPlay("macro2", 60);
iimPlay("macro3", 60);

i want to go up not in 1-2-3 steps per run - i want to go up in (for example) 15er steps like 15-30-45
i tried to edit the "for var" but it counts with 123 and ads 15 per run - looks like: 16-17-18...

what do i have to change?!
thanks for help
ABooth
Posts: 223
Joined: Mon Aug 10, 2009 4:25 pm

Re: LOOP in JavaScript

Post by ABooth » Thu Feb 18, 2010 1:03 am

mzuske wrote:thanks for helping me now i have a nother little JS problem with this script:

const iterations = 100;

for( var i=1; i<=iterations; i++)
{
iimSet("iteration", i);
iimPlay("macro1", 60);
}

iimPlay("macro2", 60);
iimPlay("macro3", 60);

i want to go up not in 1-2-3 steps per run - i want to go up in (for example) 15er steps like 15-30-45
i tried to edit the "for var" but it counts with 123 and ads 15 per run - looks like: 16-17-18...

what do i have to change?!
thanks for help

Code: Select all

const iterations = 100;
const step = 15;
const start = 15;

for( var i = start; i <= iterations; i += step)
{
   iimSet("iteration", i);
   iimPlay("macro1", 60);
}

iimPlay("macro2", 60);
iimPlay("macro3", 60);
mzuske
Posts: 24
Joined: Fri Aug 29, 2008 3:07 pm

Re: LOOP in JavaScript

Post by mzuske » Sun Jun 27, 2010 4:33 pm

thanks for the help!!!

now my "new" question is:
i have differen "interations" for example on search 1 i have 10000 on search 2 i have 12000 and so on....
how can i extract these to my const iterations - to that my macro only runs these "loops" it needs to?!

const iterations = 56000;

for( var i=1; i<=iterations; i=i+15)
{
iimSet("iteration", i);
iimPlay("macro.iim", 60);
}


thanks
Post Reply