Setting random WAIT

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
ktokuo
Posts: 3
Joined: Wed Jul 11, 2007 6:21 am

Setting random WAIT

Post by ktokuo » Thu Jul 12, 2007 4:12 am

Currently I have

Code: Select all

WAIT SECONDS=30
in between each loop.

How do I set it to random number or read from a file.

I tried

Code: Select all

WAIT SECONDS={{!COL1}} 
but it does not work.

I appreciate any comment.
yesno
Posts: 4
Joined: Fri Jul 20, 2007 4:22 pm

Post by yesno » Sat Aug 04, 2007 1:12 am

I'd like to do the same thing.

I tried every way I could think of to make it work without success.

Hopefully a tech will see this and let us know if there is a way to accomplish this.
joe_brown
Posts: 33
Joined: Mon Aug 06, 2007 8:49 pm

Use the JavaScript IF

Post by joe_brown » Sat Aug 11, 2007 2:49 pm

This is actually pretty straightforward, if you use the JS interface ..

eg:
--- demo_rndwait.js ---

Code: Select all

for(var t,i=1;i<10;i++){
 t=Math.round(10*Math.random());
 iimDisplay('Wait #'+i+': '+t+' secs');
 iimPlay('CODE:WAIT SECONDS='+t);
};
--- EO demo_rndwait.js ---

Alternatively you can create a waiting iim (say wait.iim), which does not do anything but a

Code: Select all

WAIT SECONDS={{T}}
and you run it with T set to the pre-generated pseudo-random value before invoking the waiting iim - eg (assuming a numeric t at this point):

Code: Select all

iimSet('-var_T',''+t);
iimPlay('wait',t+30);
Cheers,
Joe
yesno
Posts: 4
Joined: Fri Jul 20, 2007 4:22 pm

Post by yesno » Tue Aug 14, 2007 6:13 pm

Thanks for the reply Joe. However, it doesn't seem to be quite what I need.

I'm looping through values from a CSV file and I'd like a different wait time for each loop. So I need to load a pre-generated random time from the CSV file (which I haven't been able to do) or somehow generate a new time within each macro loop.
joe_brown
Posts: 33
Joined: Mon Aug 06, 2007 8:49 pm

Post by joe_brown » Tue Aug 14, 2007 7:56 pm

Well, my previously posted code (demo_rndwait.js) actually DOES generate a different value for the SECONDS parameter to the WAIT command on every of the 10 loops.

Everytime, when the line

Code: Select all

t=Math.round(10*Math.random());
is called, a new value for t is generated to be a random value from 0 to 10. If you need different values, its just up to you to modify the calculation of t accordingly.
- eg for random values from 15 to 60 you'd use:

Code: Select all

t=15+Math.round(45*Math.random());
If you'd really need to read the values from a file, it would be possible, but a bit more complicated, as you'd need to use java inside your javascript (since javascript should not be able to read files on your PC).
Since, however, you can code pretty much any sort of calculation within javascript, I would not really see much of a reason not to translate your algorithm you used to generate the values in your csv file to javascript and generate the values automatically when your JS macro is started.

Not sure if I've missed your point ..

Cheers,
Joe

PS: If you are using the iMacros for FX build-in Loop-Play facility, plz note, that it does not seem to work well (if at all) with javascript macros in the current latest version {VERSION BUILD=6000731 RECORDER=FX}.
User avatar
Tech Support
Posts: 4948
Joined: Tue Sep 20, 2005 7:25 pm
Contact:

Post by Tech Support » Tue Aug 14, 2007 9:19 pm

PS: If you are using the iMacros for FX build-in Loop-Play facility, plz note, that it does not seem to work well (if at all) with javascript macros in the current latest version {VERSION BUILD=6000731 RECORDER=FX}.
I can confirm this issue. But since Javascript can do its own looping, there is no need to start a Javascript with the loop button.

Solution: Instead of using Java, let iMacros read the values. You can use the Demo-Loop-CSV-2-Web macro from within your Javascript loop. You only need to replace

Code: Select all

SET !DATASOURCE_LINE {{!LOOP}} 
with

Code: Select all

SET !DATASOURCE_LINE {{!MYLOOP}}
and in the Javascript you define MYLOOP.

Code: Select all

for(var t,i=1;i<10;i++){
 iimSet ("MYLOOP", i)
 iimPlay('YourMacro');
};
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Post by figman » Thu Feb 21, 2008 4:30 pm

Tech Support wrote:
and in the Javascript you define MYLOOP.

Code: Select all

for(var t,i=1;i<10;i++){
 iimSet ("MYLOOP", i)
 iimPlay('YourMacro');
};
Is there a loop.js file or something that I can add that code to?
Where should I be putting that code? Thanks.
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Post by figman » Thu Feb 21, 2008 10:11 pm

Just to clarify, how do i call a .js file from my imacros code?
I other words how and where do i put this code:

Code: Select all

for(var t,i=1;i<10;i++){
 iimSet ("MYLOOP", i)
 iimPlay('YourMacro');
};
And what path do I use to call it?
Many thanks for helping out :?
User avatar
Tech Support
Posts: 4948
Joined: Tue Sep 20, 2005 7:25 pm
Contact:

Post by Tech Support » Sat Feb 23, 2008 1:36 am

Here is a small demo macro that uses joe_brown's suggestion:

Code: Select all

var MyMacroCode
var t
var jsNewLine="\n"

t=Math.round(10*Math.random());

MyMacroCode = "CODE:"
MyMacroCode = MyMacroCode+"URL GOTO=http://www.iopus.com" + jsNewLine
MyMacroCode = MyMacroCode+"WAIT SECONDS=" + t + jsNewLine
MyMacroCode = MyMacroCode+"URL GOTO=http://forum.imacros.net"

iimDisplay("Random wait t="+t)
iimPlay(MyMacroCode)
iimDisplay("Script completed.")
Click here to start as embedded macro.
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Post by figman » Sat Feb 23, 2008 6:56 am

I confess it takes me a long time to get my head around things sometimes (ok most times lol) :oops:

I ONLY HAVE ONE EASY PROBLEM: I CAN'T CALL JAVASCRIPT FOR NUTS!

Here is my simple question, I am using imacros with firefox and have a simple form filling code which is similar to the Demo-Loop-csv-2 now I want to to also have the "random time" setting mentioned in this thread functioning within that code.

Ready for the dumb question lol, ok how do i combine the file "my-custom-wait-code.js" with my "Demo-Loop-csv-2" code? :oops:
  • Here is what I have tried and failed:

    1) Created the file my-custom-wait-code.js with the javascript code mentioned in this thread, put it in the same directory as all the other scripts on my local machine (ie. SI-Run-Test.js) and then added "URL GOTO=PATH-TO-FILE/my-custom-wait-code.js to the bottom of "Demo-Loop-csv-2"

    2) Uploaded the file my-custom-wait-code.js to my server then added GOTO=mysite.com/my-custom-wait-code.js
These methods are stupid, sorry for that, I understand that but HOW do I call the time wait javascript (or my-custom-wait-code.js) to my customized "Demo-Loop-csv-2"??

Thanks for helping :oops:
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Post by figman » Wed Feb 27, 2008 1:25 am

Anybody :?
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Post by figman » Sun Mar 02, 2008 7:38 am

Errrm, bump. If it can't be done please just tell me guys :)
..
gojirasan
Posts: 3
Joined: Sat Feb 23, 2008 4:15 pm

Post by gojirasan » Mon Mar 03, 2008 7:28 pm

I have the same question as the OP. Is there some reason why WAIT SECONDS = {{!COL2}} doesn't work? Is this an actual bug or is it working as designed? I can't use javascript either because I *do* need to read some values from a CSV file that have nothing to do with the WAIT command and of course javascript can't read from files.
joe_brown
Posts: 33
Joined: Mon Aug 06, 2007 8:49 pm

Post by joe_brown » Tue Mar 04, 2008 1:01 am

Well, I know, this is not, what you want to hear, but javascript (ergo java) can actually read from files - eg here is one of the functions I am using in one of my iMacros:

Code: Select all

function frdln(n){
  var fr,s='';
  try{
    fr=new java.io.BufferedReader(new java.io.FileReader(n));
    s=fr.readLine();
    if(s==null){s=''}else{s=''+s};
    fr.close();
    fr=null;
  }catch(e){
    alert(''+e);
  };
  return s;
};
It accepts the filename to read from as the only parameter and returns the first line from that file (in this specific case I have the whole data in that file in one line as entries delimited by commas, therefore I did not feel the need to write anything more sophisticated..).

Cheers,
Joe
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Post by figman » Tue Mar 04, 2008 8:09 am

Still needing help with my question.
Does anyone know how to help me? Please just tell
me it can't be done so I can look at other software / alternatives,
but I need an answer please.
Post Reply