LOOP

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
TNT
Posts: 3
Joined: Tue Sep 15, 2009 1:24 pm

LOOP

Post by TNT » Wed Sep 16, 2009 11:48 am

I posted this somewhere else but no one answered i am sorry for the Dub.

Can i define the number of times i want a scrip to repeat it self in side the macro file (iim file)?

Thanks,
Marcia, Tech Support
Posts: 1095
Joined: Thu Jan 29, 2009 1:10 pm

Re: LOOP

Post by Marcia, Tech Support » Thu Sep 17, 2009 7:39 pm

Hello,

No problem, I deleted the other one. To your question:
TNT wrote:Can i define the number of times i want a scrip to repeat it self in side the macro file (iim file)?
No, you just have the option on the user interface ("Repeat Macro/Max:").
Regards,

Marcia
josephconlin
Posts: 190
Joined: Wed Aug 06, 2008 2:38 am

Re: LOOP

Post by josephconlin » Fri Sep 18, 2009 4:10 pm

Marcia, iOpus wrote:Hello,

No problem, I deleted the other one. To your question:
TNT wrote:Can i define the number of times i want a scrip to repeat it self in side the macro file (iim file)?
No, you just have the option on the user interface ("Repeat Macro/Max:").
The other option is to write a script that can call your macro in a scripting language like VBS or Javascript. You can define the loop in the scripting language to be whatever size you need, and then have it call the macro.

Hope this helps.
asda123
Posts: 4
Joined: Wed Jan 14, 2009 9:54 am

Re: LOOP

Post by asda123 » Sun Sep 20, 2009 8:00 pm

This is how to do a loop in JS, to change the amount of times it loops you change the section I have made bold and underlined. This script searches google for a random number.
var macro;
var jsLF = "\n";
var i, retcode, errtext;

for (i=0;i<=1000;i++) {

var randomnumber = Math.floor(Math.random()*1000);

/* Create the Macro */
macro = "CODE:";
macro += "URL GOTO=http://www.google.com" + jsLF;
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:f ATTR=NAME:q CONTENT=" + randomnumber + jsLF;
macro += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:f ATTR=NAME:btnG&&VALUE:Google<SP>Search" + jsLF;
macro += "WAIT SECONDS=25" + jsLF;

retcode = iimPlay(macro);
if (retcode < 0) { // an error has occured
errtext = iimGetLastError();
alert(errtext);
}

if (retcode < 0) { // an error has occured
errtext = iimGetLastError();
alert(errtext);
break;
}

}
rouge02
Posts: 10
Joined: Mon Sep 28, 2009 5:45 pm
Location: Trinidad and Tobago

Re: LOOP

Post by rouge02 » Mon Sep 28, 2009 6:04 pm

I'm getting the following error when I try to run this using iMacro

SyntaxError: unknown command: VAR at line 1
var i;
for (i=0;i<=5;i++)
{
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_TEST=i
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Save<SP>(Alt+1)&&NAME:Save&&SRC:/cs/TEST/cache/PT_SAVE_1.gif
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Next<SP>in<SP>list<SP>(Alt+3)&&NAME:Next<SP>in<SP>List&&SRC:/cs/TEST/cache/PT_NEXTINLIST_1.gif
}
If I can get this loop working it would cut down 760 lines of code into 60 flat...
Why won't it let me declare the variable "i".
I commented out the "var i;", and it gave me the same error for the "for (i=0;i<=5;i++)"
SyntaxError: unknown command: FOR at line 2
ABooth
Posts: 223
Joined: Mon Aug 10, 2009 4:25 pm

Re: LOOP

Post by ABooth » Tue Sep 29, 2009 4:11 pm

rouge02 wrote:I'm getting the following error when I try to run this using iMacro

SyntaxError: unknown command: VAR at line 1
var i;
for (i=0;i<=5;i++)
{
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_TEST=i
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Save<SP>(Alt+1)&&NAME:Save&&SRC:/cs/TEST/cache/PT_SAVE_1.gif
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Next<SP>in<SP>list<SP>(Alt+3)&&NAME:Next<SP>in<SP>List&&SRC:/cs/TEST/cache/PT_NEXTINLIST_1.gif
}
If I can get this loop working it would cut down 760 lines of code into 60 flat...
Why won't it let me declare the variable "i".
I commented out the "var i;", and it gave me the same error for the "for (i=0;i<=5;i++)"
SyntaxError: unknown command: FOR at line 2
What you're doing there is interspersing iMacros scripting language (all the TAG POS ... lines) with JavaScript. That won't work. It's like mixing Russian and Chinese in the same document and expecting the reader to know both languages and be able to determine when you switched from one to the other.

Try this: Open a text editor and paste in the following code: -

Javascript: ...\iMacros\Macros\multiPlay.js

Code: Select all

const iterations = 100; // Number of times to loop

for (var i=0; i<iterations; i++){
	iimSet('iteration', i );
	iimPlay('multiPlay');
}
Save this in your iMacros\Macros folder as multiPlay.js
NOTE the 'JS' file extension

Create a new text file and paste in the following code: -

iMacros scripting language: ...\iMacros\Macros\multiPlay.iim

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_TEST={{iteration}}
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Save<SP>(Alt+1)&&NAME:Save&&SRC:/cs/TEST/cache/PT_SAVE_1.gif
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Next<SP>in<SP>list<SP>(Alt+3)&&NAME:Next<SP>in<SP>List&&SRC:/cs/TEST/cache/PT_NEXTINLIST_1.gif
Save this in your iMacros\Macros folder as multiPlay.iim
NOTE the 'IIM' file extension

In your iMacros for Firefox plugin window, run the macro multiPlay.JS (not the iim)

The javascript executes the iMacros script and passes the iteration value to it.

You can rename the files to suit you, but remember to change the javascript file to execute the imacros script file with the name you gave it.

You can also change the number of loop iterations by changing

Loop 100 times

Code: Select all

const iterations = 100; // Number of times to loop
to something like this: -

Loop 50 times

Code: Select all

const iterations = 50; // Number of times to loop
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?
rouge02
Posts: 10
Joined: Mon Sep 28, 2009 5:45 pm
Location: Trinidad and Tobago

Re: LOOP

Post by rouge02 » Thu Oct 01, 2009 2:49 pm

Firstly thanks for your reply....
Secondly rofl @ Russian and Chinese... LoL

It would have been great if it allowed me to do just that...

If I'm reading your example correctly.. It solves the issue of my "i" increasing with each loop
But not actually looping the iMacro part of the code.

The first part of my script handles the first task, which only needs to be run once.
Then when it gets to this part;

Code: Select all

// with each loop i needs to be incremented by 1. i.e. 1-24 .. 3 lines of code to be executed 24 times, with i changing from 1-24 with each loop
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_TEST=i 
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Save<SP>(Alt+1)&&NAME:Save&&SRC:/cs/TEST/cache/PT_SAVE_1.gif
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Next<SP>in<SP>list<SP>(Alt+3)&&NAME:Next<SP>in<SP>List&&SRC:/cs/TEST/cache/PT_NEXTINLIST_1.gif
I want it to not only loop the iMacro script a specific number of times but with each loop the "i" must also increase by 1 (which is where your nice piece of code will come in handy).
I know iMacro has a general # of times to run script, but I don't want it looping the entire script. Only that section of code, once the "i" hits its target # then continue to end.

Again thanks for taking the time to reply
I'll see what I can come up with in the mean time, with what you've given me so far.
ABooth
Posts: 223
Joined: Mon Aug 10, 2009 4:25 pm

Re: LOOP

Post by ABooth » Thu Oct 01, 2009 4:58 pm

rouge02 wrote:Firstly thanks for your reply....
Secondly rofl @ Russian and Chinese... LoL

It would have been great if it allowed me to do just that...

If I'm reading your example correctly.. It solves the issue of my "i" increasing with each loop
But not actually looping the iMacro part of the code.

The first part of my script handles the first task, which only needs to be run once.
Then when it gets to this part;

Code: Select all

// with each loop i needs to be incremented by 1. i.e. 1-24 .. 3 lines of code to be executed 24 times, with i changing from 1-24 with each loop
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_TEST=i 
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Save<SP>(Alt+1)&&NAME:Save&&SRC:/cs/TEST/cache/PT_SAVE_1.gif
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Next<SP>in<SP>list<SP>(Alt+3)&&NAME:Next<SP>in<SP>List&&SRC:/cs/TEST/cache/PT_NEXTINLIST_1.gif
I want it to not only loop the iMacro script a specific number of times but with each loop the "i" must also increase by 1 (which is where your nice piece of code will come in handy).
I know iMacro has a general # of times to run script, but I don't want it looping the entire script. Only that section of code, once the "i" hits its target # then continue to end.

Again thanks for taking the time to reply
I'll see what I can come up with in the mean time, with what you've given me so far.
It will do what you want, because the Javascript piece has the loop that increments the {{iteration}} variable each time.

Here's a step by step breakdown of the javascript code

A setting for the maximum number of times the macro will be run. E.G. 100 times

Code: Select all

const iterations = 100; // Number of times to loop
Start a loop from 0 to iterations value -1, e.g 0 to (100 - 1) = 99

Code: Select all

for (var i=0; i<iterations; i++){
Create an iMacros variable called {{iteration}} with a value set to the current increment value from 0 to 99, that will be passed to the next execution of your iMacros script.

Code: Select all

   iimSet('iteration', i );
Play the macro once per loop iteration, where it gets passed the new loop iteration variable with a value from 0 to 99

Code: Select all

   iimPlay('multiPlay');
End the block of code that gets looped

Code: Select all

}
So the macro multiPlay.iim will get run 100 times and will be passed a value initially 0, but each time, gets incremented 'til the loop reaches 99


Note: If you want to go from 1 to 100 instead of 0 to 99, simply change this line of code from: -

Code: Select all

   iimSet('iteration', i );
To:-

Code: Select all

   iimSet('iteration', i  + 1);
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?
rouge02
Posts: 10
Joined: Mon Sep 28, 2009 5:45 pm
Location: Trinidad and Tobago

Re: LOOP

Post by rouge02 » Thu Oct 01, 2009 8:19 pm

Ok so I understand that, but let me give you the bigger picture here..
This first piece of code starts off my iMacro script...

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1

'TESTING URL
URL GOTO=http://testing.serv1.ttl:7110/psp/TESTING/c/MANAGE_PROCESS_(GBL).GP_RUNCTL.GBL

'SEARCH testing TEST RUN CONTROL
FRAME F=3
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:PRCSRUNCNTL_RUN_CNTL_ID CONTENT=testing
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Search<SP>(Alt+1)&&NAME:Search&&SRC:/cs/TESTING/cache/PT_SEARCH_1.gif
WAIT SECONDS=2

'SELECT testing01 FROM SEARCH RESULTS
TAG POS=1 TYPE=A ATTR=CLASS:PSSRCHRESULTSODDROW&&TABINDEX:34&&HREF:javascript:<SP>submitAction_win0(document,'win0','#ICRow12');
Once complete it continues to the following, and this entire section of code needs to be looped 24 times.
And "i" needs to be changed from 1 - 24 with each loop.. <=which i understand how to do based on what you've given me

Code: Select all

'ENTER CALENDAR GROUP ID
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_RUNCTL_CAL_RUN_ID CONTENT=TESTING009
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:absmiddle&&ALT:Look<SP>up<SP>Calendar<SP>Group<SP>ID<SP>(Alt+5)&&SRC:/cs/TESTING/cache/PT_PROMPT_LOOKUP_1.gif
WAIT SECONDS=2
TAG POS=1 TYPE=A ATTR=CLASS:PSSRCHRESULTSODDROW&&TABINDEX:21&&HREF:javascript:<SP>submitAction_win0(document,'win0','#ICRow0');&&NAME:SEARCH_RESULT1

'SELECT IDENTIFY + CALCULATE + RECALCULATE
FRAME F=3
WAIT SECONDS=1
TAG POS=1 TYPE=LABEL ATTR=CLASS:PSCHECKBOX&&FOR:GP_RUNCTL_RUN_IDNT_IND
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:win0 ATTR=ID:GP_RUNCTL_RUN_IDNT_IND CONTENT=YES
WAIT SECONDS=1
TAG POS=1 TYPE=LABEL ATTR=CLASS:PSCHECKBOX&&FOR:GP_RUNCTL_RUN_CALC_IND$24$
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:win0 ATTR=ID:GP_RUNCTL_RUN_CALC_IND$24$ CONTENT=YES
WAIT SECONDS=1
TAG POS=1 TYPE=LABEL ATTR=CLASS:PSCHECKBOX&&FOR:GP_RUNCTL_RUN_RECALC_ALL_IND
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:win0 ATTR=ID:GP_RUNCTL_RUN_RECALC_ALL_IND CONTENT=YES
WAIT SECONDS=1

'STREAM #1 of 24
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_RUNCTL_STRM_NUM CONTENT=i

'SAVE PARAMETERS
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Save<SP>(Alt+1)&&NAME:Save&&SRC:/cs/TESTING/cache/PT_SAVE_1.gif

WAIT SECONDS=2

'GO TO  NEXT IN LIST
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Next<SP>in<SP>list<SP>(Alt+3)&&NAME:Next<SP>in<SP>List&&SRC:/cs/TESTING/cache/PT_NEXTINLIST_1.gif

'END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-
'NOTE AT THE POINT WHERE IT SAYS 'STREAM #1 of 24 THAT CODE POSTED WILL COME INTO PLAY HERE TO INCREASE
THE VALUE OF i BY 1 AT EACH LOOP


So I was thinking either I separate the first piece of code from the second and insert a call to the second piece of code so that
I can use iMacro's Repeat, to repeat the whole of the second macro, X amount of times.

Or figure out how to loop the 2nd piece of code 24 times.. and still
use your code to change the value of i from 1 - 24 respectively.
ABooth
Posts: 223
Joined: Mon Aug 10, 2009 4:25 pm

Re: LOOP

Post by ABooth » Fri Oct 02, 2009 3:40 am

That can be easily achieved with a small change.

Separate the part before the loop and save it as preLoop.iim

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1

'TESTING URL
URL GOTO=http://testing.serv1.ttl:7110/psp/TESTING/c/MANAGE_PROCESS_(GBL).GP_RUNCTL.GBL

'SEARCH testing TEST RUN CONTROL
FRAME F=3
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:PRCSRUNCNTL_RUN_CNTL_ID CONTENT=testing
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Search<SP>(Alt+1)&&NAME:Search&&SRC:/cs/TESTING/cache/PT_SEARCH_1.gif
WAIT SECONDS=2

'SELECT testing01 FROM SEARCH RESULTS
TAG POS=1 TYPE=A ATTR=CLASS:PSSRCHRESULTSODDROW&&TABINDEX:34&&HREF:javascript:<SP>submitAction_win0(document,'win0','#ICRow12');

'ENTER CALENDAR GROUP ID
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_RUNCTL_CAL_RUN_ID CONTENT=TESTING009
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:absmiddle&&ALT:Look<SP>up<SP>Calendar<SP>Group<SP>ID<SP>(Alt+5)&&SRC:/cs/TESTING/cache/PT_PROMPT_LOOKUP_1.gif
WAIT SECONDS=2
TAG POS=1 TYPE=A ATTR=CLASS:PSSRCHRESULTSODDROW&&TABINDEX:21&&HREF:javascript:<SP>submitAction_win0(document,'win0','#ICRow0');&&NAME:SEARCH_RESULT1

'SELECT IDENTIFY + CALCULATE + RECALCULATE
FRAME F=3
WAIT SECONDS=1
TAG POS=1 TYPE=LABEL ATTR=CLASS:PSCHECKBOX&&FOR:GP_RUNCTL_RUN_IDNT_IND
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:win0 ATTR=ID:GP_RUNCTL_RUN_IDNT_IND CONTENT=YES
WAIT SECONDS=1
TAG POS=1 TYPE=LABEL ATTR=CLASS:PSCHECKBOX&&FOR:GP_RUNCTL_RUN_CALC_IND$24$
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:win0 ATTR=ID:GP_RUNCTL_RUN_CALC_IND$24$ CONTENT=YES
WAIT SECONDS=1
TAG POS=1 TYPE=LABEL ATTR=CLASS:PSCHECKBOX&&FOR:GP_RUNCTL_RUN_RECALC_ALL_IND
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:win0 ATTR=ID:GP_RUNCTL_RUN_RECALC_ALL_IND CONTENT=YES
WAIT SECONDS=1
Then save the loop section as loopSection.iim Note: I replaced CONTENT=i with CONTENT={{i}} because {{i}} is now passed from JavaScript to the iMacros script

Code: Select all

'STREAM #1 of 24
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_RUNCTL_STRM_NUM CONTENT={{i}}
Then save the rest as postLoop.iim

Code: Select all

'SAVE PARAMETERS
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Save<SP>(Alt+1)&&NAME:Save&&SRC:/cs/TESTING/cache/PT_SAVE_1.gif

WAIT SECONDS=2

'GO TO  NEXT IN LIST
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Next<SP>in<SP>list<SP>(Alt+3)&&NAME:Next<SP>in<SP>List&&SRC:/cs/TESTING/cache/PT_NEXTINLIST_1.gif

'END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-

Then modify your JavaScript to run all 3 iMacros

Code: Select all

const iterations = 24; // Number of times to loop

//Run the bit before the loop
iimPlay('preLoop');

//Start Of Loop
for (var i=0; i<iterations; i++){
   iimSet('i', i + 1); //increment {{i}} each time 1 to 24
   iimPlay('loopSection');
} // End Of Loop

// Run the bit after the loop
iimPlay('postLoop');
If everything from 'STREAM #1 of 24 onwards is needed in the loop, do this

Separate the part before the loop and save it as preLoop.iim

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1

'TESTING URL
URL GOTO=http://testing.serv1.ttl:7110/psp/TESTING/c/MANAGE_PROCESS_(GBL).GP_RUNCTL.GBL

'SEARCH testing TEST RUN CONTROL
FRAME F=3
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:PRCSRUNCNTL_RUN_CNTL_ID CONTENT=testing
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Search<SP>(Alt+1)&&NAME:Search&&SRC:/cs/TESTING/cache/PT_SEARCH_1.gif
WAIT SECONDS=2

'SELECT testing01 FROM SEARCH RESULTS
TAG POS=1 TYPE=A ATTR=CLASS:PSSRCHRESULTSODDROW&&TABINDEX:34&&HREF:javascript:<SP>submitAction_win0(document,'win0','#ICRow12');

'ENTER CALENDAR GROUP ID
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_RUNCTL_CAL_RUN_ID CONTENT=TESTING009
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:absmiddle&&ALT:Look<SP>up<SP>Calendar<SP>Group<SP>ID<SP>(Alt+5)&&SRC:/cs/TESTING/cache/PT_PROMPT_LOOKUP_1.gif
WAIT SECONDS=2
TAG POS=1 TYPE=A ATTR=CLASS:PSSRCHRESULTSODDROW&&TABINDEX:21&&HREF:javascript:<SP>submitAction_win0(document,'win0','#ICRow0');&&NAME:SEARCH_RESULT1

'SELECT IDENTIFY + CALCULATE + RECALCULATE
FRAME F=3
WAIT SECONDS=1
TAG POS=1 TYPE=LABEL ATTR=CLASS:PSCHECKBOX&&FOR:GP_RUNCTL_RUN_IDNT_IND
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:win0 ATTR=ID:GP_RUNCTL_RUN_IDNT_IND CONTENT=YES
WAIT SECONDS=1
TAG POS=1 TYPE=LABEL ATTR=CLASS:PSCHECKBOX&&FOR:GP_RUNCTL_RUN_CALC_IND$24$
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:win0 ATTR=ID:GP_RUNCTL_RUN_CALC_IND$24$ CONTENT=YES
WAIT SECONDS=1
TAG POS=1 TYPE=LABEL ATTR=CLASS:PSCHECKBOX&&FOR:GP_RUNCTL_RUN_RECALC_ALL_IND
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:win0 ATTR=ID:GP_RUNCTL_RUN_RECALC_ALL_IND CONTENT=YES
WAIT SECONDS=1
Then save the loop section as loopSection.iim Note: I replaced CONTENT=i with CONTENT={{i}} because {{i}} is now passed from JavaScript to the iMacros script

Code: Select all

'STREAM #1 of 24
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:win0 ATTR=ID:GP_RUNCTL_STRM_NUM CONTENT={{i}}

'SAVE PARAMETERS
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Save<SP>(Alt+1)&&NAME:Save&&SRC:/cs/TESTING/cache/PT_SAVE_1.gif

WAIT SECONDS=2

'GO TO  NEXT IN LIST
TAG POS=1 TYPE=IMG ATTR=BORDER:0&&ALIGN:middle&&ALT:Next<SP>in<SP>list<SP>(Alt+3)&&NAME:Next<SP>in<SP>List&&SRC:/cs/TESTING/cache/PT_NEXTINLIST_1.gif

'END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-OF-STREAM~END-

Then modify your JavaScript to run both iMacros

Code: Select all

const iterations = 24; // Number of times to loop

//Run the bit before the loop
iimPlay('preLoop');

//Start Of Loop
for (var i=0; i<iterations; i++){
   iimSet('i', i + 1); //increment {{i}} each time 1 to 24
   iimPlay('loopSection');
} // End Of Loop
Note: No post loop section.
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?
ng.tinyreef
Posts: 17
Joined: Thu Oct 22, 2009 8:29 pm

Re: LOOP

Post by ng.tinyreef » Mon May 10, 2010 5:34 pm

Great Topic!

Quick question though


How would I tell the script to loop between a number range

ie.


I want to loop between lines 25-40 on my csv file
is there an easy way to tell the javascript how to do this?
rouge02
Posts: 10
Joined: Mon Sep 28, 2009 5:45 pm
Location: Trinidad and Tobago

Re: LOOP

Post by rouge02 » Tue May 11, 2010 3:21 am

Hi ng.tinyreef, can we get a little more info about your csv file. off the bat i'm thinking for you to just put lines 25-40 in a separate csv file..
or just use the { } brackets to isolate that part of the script, but as i've learned with my inatial loop issue it's never quite that simple..


as my boy Murphy would say;
--every solution breeds new problems
--there's always one more bug
MattBell7
Posts: 627
Joined: Thu Nov 26, 2009 11:07 am
Location: United Kingdom

Re: LOOP

Post by MattBell7 » Fri May 14, 2010 12:28 pm

Code: Select all

for (var i=25; i<=40; i++){
   iimSet('i', i); //increment {{i}} each time 25 to 40
   iimPlay('loopSection');
}
tada
rouge02
Posts: 10
Joined: Mon Sep 28, 2009 5:45 pm
Location: Trinidad and Tobago

Re: LOOP

Post by rouge02 » Fri May 14, 2010 11:27 pm

I don't think that is quite what he had in mind.

He said;
ng.tinyreef wrote: ....cut....
I want to loop between lines 25-40 on my csv file
is there an easy way to tell the javascript how to do this?
Looping lines of script is another matter altogether.
As i was corrected earlier for mixing iMacro script and javascript;
ABooth wrote:...cut... What you're doing there is interspersing iMacros scripting language (all the TAG POS ... lines) with JavaScript. That won't work. It's like mixing Russian and Chinese in the same document and expecting the reader to know both languages and be able to determine when you switched from one to the other.
xNeroX
Posts: 1
Joined: Sun Apr 03, 2011 4:14 am

Re: LOOP

Post by xNeroX » Sun Apr 03, 2011 4:18 am

A neat trick to script a loop into the macro itself. use this
SET !LOOP -500
(This will trick the Macro into repeating 500 times)
Post Reply