looping and js

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
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

looping and js

Post by questions » Fri Jan 16, 2009 6:58 am

can someone post some sample code that loops through a series actions x times then pauses y seconds then loops through another set of actions z times?

also is there a place that lists sample js and vb code for the free version of imacros?
additional001
Posts: 175
Joined: Sun Jul 06, 2008 3:24 am

Re: looping and js

Post by additional001 » Fri Jan 16, 2009 10:13 am

The closest thing I have to what you are asking for is this.

Code: Select all

var StarU;
var i;
var MaxStars = 200;
var nL = "\n";

for (i = 1; i <= MaxStars; i++ )
{
StarU = "CODE:"
StarU = StarU+"SET !VAR1 w00t<SP>I<SP>do<SP>have<SP>a<SP>short<SP>attention<SP>OHHH<SP>SHINEY!" + nL
StarU = StarU+"TAG POS=1 TYPE=A ATTR=TXT:Give<SP>a<SP>Gold<SP>Star<SP>Back" + nL
StarU = StarU+"TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:reasontext CONTENT={{!VAR1}}" + nL
StarU = StarU+"TAG POS=1 TYPE=IMG ATTR=SRC:*btn_submit.gif" + nL
StarU = StarU+"TAG POS=1 TYPE=IMG ATTR=SRC:http://assets.myyearbook.com/updateicons/notifications_x.gif" + nL
StarU = StarU+"TAG POS=1 TYPE=IMG ATTR=SRC:http://assets.myyearbook.com//btn_ok.gif" + nL
iimPlay(StarU)
}
I'm not sure what kind of "pause" you are looking for...

VBS codes are scattered all through the wiki and you can find some in the trial version. Javascript is a little harder to come by. Most of which you can find by following the URL below

http://wiki.imacros.net/iMacros_for_Fir ... _Interface

Also looking over a few DEMO scripts wouldn't hurt
dharmendra2000
Posts: 214
Joined: Fri Jul 04, 2008 1:28 pm
Location: Ahmedabad
Contact:

Re: looping and js

Post by dharmendra2000 » Fri Jan 16, 2009 1:11 pm

Code: Select all

for(i=0;i<10;i++)
{
iimPlay("Action1.iim)
}

iimPlay("WaitMacro.iim")

for(i=0;i<10;i++)
{
iimPlay("Action2.iim")
}

iimPlay("WaitMacro.iim")
Write just wait command in "WaitMaco.iim" like WAIT SECONDS=10

Hope it will help in solving you problem
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

Re: looping and js

Post by questions » Fri Jan 16, 2009 7:08 pm

im just having a little trouble figuring out how you combine script with the imacros commands and then determining which are available in the free version since i dont have the paid version.
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

Re: looping and js

Post by questions » Fri Jan 16, 2009 7:11 pm

can you replace

iimPlay("WaitMacro.iim")

with a single wait command instead of calling another macro?

WAIT SECONDS=60


dharmendra2000 wrote:

Code: Select all

for(i=0;i<10;i++)
{
iimPlay("Action1.iim)
}

iimPlay("WaitMacro.iim")

for(i=0;i<10;i++)
{
iimPlay("Action2.iim")
}

iimPlay("WaitMacro.iim")
Write just wait command in "WaitMaco.iim" like WAIT SECONDS=10

Hope it will help in solving you problem
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

Re: looping and js

Post by questions » Fri Jan 16, 2009 7:14 pm

dharmendra2000 wrote:

Code: Select all

for(i=0;i<10;i++)
{
iimPlay("Action1.iim)
}

iimPlay("WaitMacro.iim")

for(i=0;i<10;i++)
{
iimPlay("Action2.iim")
}

iimPlay("WaitMacro.iim")
Write just wait command in "WaitMaco.iim" like WAIT SECONDS=10

Hope it will help in solving you problem

i think the following is more what i'm looking for, i dont write much js or vb so i dont know if you can use caps or different variable names...

FOR(j=0;j<10;j++)

{

for(i=0;i<10;i++)
{
iimPlay("Action1.iim)
}

WAIT SECONDS=60

for(i=0;i<10;i++)
{
iimPlay("Action2.iim")
}


}




will that work?
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

Re: looping and js

Post by questions » Fri Jan 16, 2009 10:32 pm

SyntaxError: bad format of macro line: for(i=0;i<10;i++;), line 1



if i remove the ; like you had it posted then it says




SyntaxError: bad format of macro line: for(i=0;i<10;i++), line 1
josephconlin
Posts: 190
Joined: Wed Aug 06, 2008 2:38 am

Re: looping and js

Post by josephconlin » Fri Jan 16, 2009 10:34 pm

The short answer to your question is that there is no Javascript way to sleep or wait, and you cannot execute iMacros commands directly inside Javascript. Now for the long answer. :D

You're very close with what you posted. What often gets lots in the shuffle with Javascript and iMacros is that you can use Javascript to call iMacros macros, but you CAN'T use iMacros commands directly in Javascript - you have to use the Javascript calls into the iMacros interface. The link that additional001 provided is a good place to learn some of this.

So, what can you do in Javascript? You can loop, define variables, and most standard kinds of programming things (not sleep, though, at least not easily). What can you do in iMacros? You can visit and interact with web pages, including extracting information from them, you can sleep via WAIT SECONDS, and generally do browser things.

So, how do we combine these two things to accomplish what we want? There are two ways.

1) Write/record the macros, and then have Javascript call iMacros with the existing macro file.
2) Write the macro as a variable in Javascript, and then have Javascript call iMacros with the variable that contains the macro.

As you can see, in both cases, you have to call iMacros to do the macro work, but you can either write/record the macro outside of the Javascript file or inside of it. It's up to you.

Here's an example that combines the two ways, and is pretty much taken from the samples posted here before.

Code: Select all

var i;
var j;
var macro;

for(j=0;j<10;j++)
{
    for(i=0;i<10;i++)
    {
        iimPlay("Action1.iim);    //This is an example of calling a macro file that already exists
    }

    //Now write a macro and store it in a variable to be sent to iMacros by the iimPlay function.  
    //This is what additional001 is doing in the sample he/she posted.
    macro="CODE:WAIT SECONDS=60\n";    //The \n on a single line macro might not be needed
    iimPlay(macro);

    for(i=0;i<10;i++)
    {
        iimPlay("Action2.iim");    //This is another macro file that already exists
    }

}
Hope that gets you on your way. Thanks to dharmendra2000 and additional001 for providing the code I used! :mrgreen:
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

Re: looping and js

Post by questions » Fri Jan 16, 2009 10:42 pm

ok you have to name js files .js or they dont work, now it works but you also have to have different variable names if the look is inside a loop (in my case i for the inside loops and j for the outside loop):

this code repeats something 3 times with a pause between it, note you must name it .js



for(j=0;j<3;j++)

{




for(i=0;i<3;i++)
{
iimPlay("a.iim")
}





iimPlay("wait.iim")





}
questions
Posts: 69
Joined: Wed Apr 23, 2008 9:23 pm

Re: looping and js

Post by questions » Fri Jan 16, 2009 10:52 pm

does VB work inside the free imacros for firefox? if so can someone past code to do the same thing using VB?
additional001
Posts: 175
Joined: Sun Jul 06, 2008 3:24 am

Re: looping and js

Post by additional001 » Fri Jan 16, 2009 11:35 pm

questions wrote:does VB work inside the free imacros for firefox? if so can someone past code to do the same thing using VB?
I don't know if you can use Visual Basic within a macro... I know you can use Visual Basic Script or VBS.. I think you can find some .VBS demos... and there is some example code in the wiki... however VBS is not my forte... Tech Support could prob help you... if you can get them to respond. They tend to like that VBS stuff(I'm guessing cuz the put examples in the wiki but not JS ones).
dharmendra2000
Posts: 214
Joined: Fri Jul 04, 2008 1:28 pm
Location: Ahmedabad
Contact:

Re: looping and js

Post by dharmendra2000 » Sat Jan 17, 2009 10:06 am

WAIT SECONDS=60
Instead of writing this in Java Script, you can call Macro which is containg 'WAIT SECONDS=60'
additional001
Posts: 175
Joined: Sun Jul 06, 2008 3:24 am

Re: looping and js

Post by additional001 » Sat Jan 17, 2009 10:26 pm

questions wrote:im just having a little trouble figuring out how you combine script with the imacros commands and then determining which are available in the free version since i dont have the paid version.
http://wiki.imacros.net/Command_Reference If you read at the very top it tells you about the icons.. the icons tell you on each command what versions each command works in. Though honestly this thing needs updating... it's all we got.

http://wiki.imacros.net/iMacros_for_Fir ... _InterfaceNotice the URL name? This section contains everything for the FF plugin on Javascript (not saying that you don't have to follow the links on the page to learn more... but this is where to start.)

http://wiki.imacros.net/iimPlay You can follow this from the above link. This explains to ya how to "call" other macros or to "nest" iim code into JS. Read the first section and the Parameters section. Oh yeah and you were looking for VBS examples... look here. Personally I always thought it kinda dumb to have this linked from the Javascript Scripting Interface for FF's page and not have any JS examples on it... but what do I know.
additional001
Posts: 175
Joined: Sun Jul 06, 2008 3:24 am

Re: looping and js

Post by additional001 » Sat Jan 17, 2009 10:58 pm

Ok so I guess this WAIT SECONDS is still an issue with you... so I'm going to try to knock this out for you. You have two options.. you can nest the code within your javascript... or you could store a WAIT SECONDS=60 command in a iim macro to be called I'll show you both

NESTING

Code: Select all

var _wait;
var nL = "\n"

for(i=0;i<10;i++)
      {
      iimPlay("Action1.iim)
}

_wait = "CODE:"
_wait = _wait+"WAIT SECONDS=60" + nL 

for(i=0;i<10;i++)
     {
     iimPlay("Action2.iim")
}
Additionally you could nest the contents of Action1.iim and Action2.iim in the same way... since I don't know the contents of them.. hard for me to show that.

CALLING

Code: Select all

for(i=0;i<10;i++)
     {
     iimPlay("Action1.iim")
}

iimPlay("Wait.iim")

for(i=0;i<10;i++)
     {
     iimPlay("Action2.iim")
}
}
Wait.iim

Code: Select all

WAIT SECONDS=60
dharmendra2000
Posts: 214
Joined: Fri Jul 04, 2008 1:28 pm
Location: Ahmedabad
Contact:

Re: looping and js

Post by dharmendra2000 » Tue Jan 20, 2009 5:51 am

Solution provided by additional001 is correct......
Below are my inputs to make picture more clear
YourScript.js

Code: Select all

for(i=0;i<10;i++)
{
     iimPlay("Action1.iim")
}

iimPlay("Wait.iim")

for(i=0;i<10;i++)
{
     iimPlay("Action2.iim")
}
Wait.iim

Code: Select all

WAIT SECONDS=60
Now when both file (YourScript.js and Wait.iim) are ready with you select 'YourScript.js' and click on Play button.
1.iimPlay("Action1.iim") will call Action1.iim, 10 times
2.iimPlay("Wait.iim") will call Wait.iim once, it will stop your macro for 10 second
3.iimPlay("Action2.iim") will call Action1.iim, 10 times

Hope it will solve your purpose.
Post Reply