Help for Random Wait Time.

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
ABooth
Posts: 223
Joined: Mon Aug 10, 2009 4:25 pm

Re: Help for Random Wait Time.

Post by ABooth » Fri Nov 13, 2009 6:20 pm

josephconlin wrote:
SorenC wrote:Hey guys. :)

Thanx for your assistance.

Now i have another problem.

It seems like the randomWait.js only runs once. It goes through the macro and then stops after executing the macro. But i need it to run X number of times. I know there is some looping code for JS, that i need to use.

But how do i implament it into the current javascript that i have?

Code: Select all

iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
iret = iimPlay("randomWait.iim");
I have tried this:

Code: Select all

var i=1;
for (i=1;i<=3;i++)
iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
iret = iimPlay("test.iim");
But it dosnt seem to do the trick. :(
You need curly braces ( { } ) around the part you want to be looped. Try this.

Code: Select all

var i=1;
for (i=1;i<=3;i++)
{
    iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
    iret = iimPlay("test.iim");
}
Without the curly braces, your command is interpreted as whatever is on this single line gets looped, so your loop just counts from 1 to 3 and then moves on to the iimSet line. You want the iimSet and the iimPlay parts to be looped over, so you have to enclose them inside the curly braces.

Hope this helps.
Actually, JavaScript is a 'C' style language, where all commands are terminated by a semi colon, except for block syntax that combines multiple lines into 1.
What happened above

Code: Select all

var i=1;
for (i=1;i<=3;i++)
iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
iret = iimPlay("test.iim");
Was the equivalent of this: -

Code: Select all

var i=1;
for (i=1;i<=3;i++){
    iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
}
iret = iimPlay("test.iim");
So it set the value of the randomWait variable twice (looping 1 to less than 3 = 1 to 2)
Then it ran the script.

What you were suggesting would have been this: -

Code: Select all

var i=1;
for (i=1;i<=3;i++); // Added a semi-colon here
iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
iret = iimPlay("test.iim");
Note: getting the return value in iret is unnecessary if you're not doing anything with it, so you may as well do this:-

Code: Select all

const iterations = 2;
for (var i=0; i<=iterations; i++){
    iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
    iimPlay("test.iim");
}
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?
SorenC
Posts: 36
Joined: Wed Oct 28, 2009 4:33 pm

Re: Help for Random Wait Time.

Post by SorenC » Sat Nov 14, 2009 12:43 pm

Okey guys. A new problem has been discovered.

This is my macro:

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1
CLEAR
SET !ERRORIGNORE YES
CMDLINE !DATASOURCE users.csv
SET !DATASOURCE_COLUMNS 2
SET !LOOP 5
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=http://www.facebook.com/
TAG POS=1 TYPE=A ATTR=TXT:English<SP>(US)
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:email CONTENT={{!COL1}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:pass CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:login_form ATTR=VALUE:Login
URL GOTO=http://genau.dk/aaretstatovering/voteny.php?unik_idnr=118
FRAME F=0
TAG POS=1 TYPE=A ATTR=TXT:Logout
WAIT SECONDS=200
and then im using this javascript:

Code: Select all

var i=1;
for (i=1;i<=316;i++)
{
    iret = iimSet("randomWait", Math.floor((Math.random()*180)+60).toString() );
    iret = iimPlay("FacebookVote.iim");
}
But it seems to be stuck at the 2nd line in the cvs file?. It only runs the 2nd line in the users.cvs file.

How do i get it to go to the next line in the cvs file??
ABooth
Posts: 223
Joined: Mon Aug 10, 2009 4:25 pm

Re: Help for Random Wait Time.

Post by ABooth » Mon Nov 16, 2009 3:31 pm

SorenC wrote:Okey guys. A new problem has been discovered.

This is my macro:

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1
CLEAR
SET !ERRORIGNORE YES
CMDLINE !DATASOURCE users.csv
SET !DATASOURCE_COLUMNS 2
SET !LOOP 5
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=http://www.facebook.com/
TAG POS=1 TYPE=A ATTR=TXT:English<SP>(US)
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:email CONTENT={{!COL1}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:pass CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:login_form ATTR=VALUE:Login
URL GOTO=http://genau.dk/aaretstatovering/voteny.php?unik_idnr=118
FRAME F=0
TAG POS=1 TYPE=A ATTR=TXT:Logout
WAIT SECONDS=200
and then im using this javascript:

Code: Select all

var i=1;
for (i=1;i<=316;i++)
{
    iret = iimSet("randomWait", Math.floor((Math.random()*180)+60).toString() );
    iret = iimPlay("FacebookVote.iim");
}
But it seems to be stuck at the 2nd line in the cvs file?. It only runs the 2nd line in the users.cvs file.

How do i get it to go to the next line in the cvs file??
Is iMacros providing the loop for the CSV file? If so, you're only running the script once, but several times (if that makes sense?)

in other words: if you tell iMacros to run a macro several times, it increments the {{LOOP}} variable internally. If you run the iMacro several times through javascript each run is a separate instance.

To increment the loop counter, you should pass the row number to the imacro (as you did with "randomWait") and set the loop start with this value using

Code: Select all

SET !LOOP {{csvRow}}
for example.


here would be the complete JavaScript code

Code: Select all

const totalIterations = 315; // How many times to loop
const startRow = 5; // Which row of the CSV file to start on

for (var i=0 ; i<=totalIterations; i++)
{
    var csvRow = i + startRow; 
    iimSet("randomWait", Math.floor((Math.random()*180)+60).toString() );
    iimSet("csvRow", csvRow.toString() );
    iimPlay("FacebookVote.iim");
}
and in your macro, you would have: -

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1
CLEAR
SET !ERRORIGNORE YES
CMDLINE !DATASOURCE users.csv
SET !DATASOURCE_COLUMNS 2

' *********************** The line below has been changed  *********************** 
SET !LOOP {{csvRow}}
' ***************************************************************************************

SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=http://www.facebook.com/
TAG POS=1 TYPE=A ATTR=TXT:English<SP>(US)
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:email CONTENT={{!COL1}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:pass CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:login_form ATTR=VALUE:Login
URL GOTO=http://genau.dk/aaretstatovering/voteny.php?unik_idnr=118
FRAME F=0
TAG POS=1 TYPE=A ATTR=TXT:Logout
WAIT SECONDS=200
You would probably want to use the {{randomWait}} variable in there somewhere too. :wink:
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?
SorenC
Posts: 36
Joined: Wed Oct 28, 2009 4:33 pm

Re: Help for Random Wait Time.

Post by SorenC » Mon Nov 16, 2009 5:43 pm

ABooth wrote:
SorenC wrote:Okey guys. A new problem has been discovered.

This is my macro:

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1
CLEAR
SET !ERRORIGNORE YES
CMDLINE !DATASOURCE users.csv
SET !DATASOURCE_COLUMNS 2
SET !LOOP 5
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=http://www.facebook.com/
TAG POS=1 TYPE=A ATTR=TXT:English<SP>(US)
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:email CONTENT={{!COL1}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:pass CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:login_form ATTR=VALUE:Login
URL GOTO=http://genau.dk/aaretstatovering/voteny.php?unik_idnr=118
FRAME F=0
TAG POS=1 TYPE=A ATTR=TXT:Logout
WAIT SECONDS=200
and then im using this javascript:

Code: Select all

var i=1;
for (i=1;i<=316;i++)
{
    iret = iimSet("randomWait", Math.floor((Math.random()*180)+60).toString() );
    iret = iimPlay("FacebookVote.iim");
}
But it seems to be stuck at the 2nd line in the cvs file?. It only runs the 2nd line in the users.cvs file.

How do i get it to go to the next line in the cvs file??
Is iMacros providing the loop for the CSV file? If so, you're only running the script once, but several times (if that makes sense?)

in other words: if you tell iMacros to run a macro several times, it increments the {{LOOP}} variable internally. If you run the iMacro several times through javascript each run is a separate instance.

To increment the loop counter, you should pass the row number to the imacro (as you did with "randomWait") and set the loop start with this value using

Code: Select all

SET !LOOP {{csvRow}}
for example.


here would be the complete JavaScript code

Code: Select all

const totalIterations = 315; // How many times to loop
const startRow = 5; // Which row of the CSV file to start on

for (var i=0 ; i<=totalIterations; i++)
{
    var csvRow = i + startRow; 
    iimSet("randomWait", Math.floor((Math.random()*180)+60).toString() );
    iimSet("csvRow", csvRow.toString() );
    iimPlay("FacebookVote.iim");
}
and in your macro, you would have: -

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1
CLEAR
SET !ERRORIGNORE YES
CMDLINE !DATASOURCE users.csv
SET !DATASOURCE_COLUMNS 2

' *********************** The line below has been changed  *********************** 
SET !LOOP {{csvRow}}
' ***************************************************************************************

SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=http://www.facebook.com/
TAG POS=1 TYPE=A ATTR=TXT:English<SP>(US)
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:email CONTENT={{!COL1}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:pass CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:login_form ATTR=VALUE:Login
URL GOTO=http://genau.dk/aaretstatovering/voteny.php?unik_idnr=118
FRAME F=0
TAG POS=1 TYPE=A ATTR=TXT:Logout
WAIT SECONDS=200
You would probably want to use the {{randomWait}} variable in there somewhere too. :wink:
The {{randomWait}} would be used at the last "WAIT SECONDS=". So that it picks a random number of secs to wait before running the macro again.

And yes. The macro tells IMacros, that when it runs the macro again, it takes the next email/password from the users.cvs file.

I'll try the javascript that you made and then get back to you. :)
SorenC
Posts: 36
Joined: Wed Oct 28, 2009 4:33 pm

Re: Help for Random Wait Time.

Post by SorenC » Mon Nov 16, 2009 5:54 pm

It seems to be working fine at the moment. :)

So once again thank you very much for your help :D
josephconlin
Posts: 190
Joined: Wed Aug 06, 2008 2:38 am

Re: Help for Random Wait Time.

Post by josephconlin » Mon Nov 16, 2009 10:59 pm

ABooth wrote: Actually, JavaScript is a 'C' style language, where all commands are terminated by a semi colon, except for block syntax that combines multiple lines into 1.
What happened above

Code: Select all

var i=1;
for (i=1;i<=3;i++)
iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
iret = iimPlay("test.iim");
Was the equivalent of this: -

Code: Select all

var i=1;
for (i=1;i<=3;i++){
    iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
}
iret = iimPlay("test.iim");
So it set the value of the randomWait variable twice (looping 1 to less than 3 = 1 to 2)
Then it ran the script.

What you were suggesting would have been this: -

Code: Select all

var i=1;
for (i=1;i<=3;i++); // Added a semi-colon here
iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
iret = iimPlay("test.iim");
...
Cool! Thanks for pointing that out, as I was obviously incorrect in my understanding of the actual mechanism.

As a side note to your side note, his loop actually goes through 3 times because it's looping 1 to less than or equal to 3. :)
ABooth
Posts: 223
Joined: Mon Aug 10, 2009 4:25 pm

Re: Help for Random Wait Time.

Post by ABooth » Tue Nov 17, 2009 1:51 pm

josephconlin wrote:
ABooth wrote: Actually, JavaScript is a 'C' style language, where all commands are terminated by a semi colon, except for block syntax that combines multiple lines into 1.
What happened above

Code: Select all

var i=1;
for (i=1;i<=3;i++)
iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
iret = iimPlay("test.iim");
Was the equivalent of this: -

Code: Select all

var i=1;
for (i=1;i<=3;i++){
    iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
}
iret = iimPlay("test.iim");
So it set the value of the randomWait variable twice (looping 1 to less than 3 = 1 to 2)
Then it ran the script.

What you were suggesting would have been this: -

Code: Select all

var i=1;
for (i=1;i<=3;i++); // Added a semi-colon here
iret = iimSet("randomWait", Math.floor((Math.random()*160)+100).toString() );
iret = iimPlay("test.iim");
...
Cool! Thanks for pointing that out, as I was obviously incorrect in my understanding of the actual mechanism.

As a side note to your side note, his loop actually goes through 3 times because it's looping 1 to less than or equal to 3. :)
You are correct. I usually use 0 based loops (i=0; i<maxValue; i++) . My eyes didn't see the =

It's weird how your eyes (brain) filter for you. It's like a built in bug generator :D . Good spot.
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?
bugmenot666
Posts: 39
Joined: Wed Apr 08, 2009 2:01 pm

Re: Help for Random Wait Time.

Post by bugmenot666 » Thu Aug 23, 2012 11:32 am

infoleather
Posts: 2
Joined: Mon Sep 10, 2012 3:04 am
Location: New York
Contact:

Re: Help for Random Wait Time.

Post by infoleather » Mon Sep 10, 2012 3:39 am

Through the macro, and then stopped after the execution of the macro. But I need it to run X times.
The size of Women Purple Leather Shoulder bags also depends upon the needs of women. If you are working women who has to go her office daily then you may need cwmalls.com Women Leather Flap Messenger Bags that can contain files and gadgets.
Post Reply