General :  K-Meleon Forum
General discussion about K-Meleon. 
If . . Then statement in Macro Language
Posted by: James
Date: July 29, 2007 02:32AM

I cannot seem to find an "If...Then" statement in the macro language documentation. I have found a "While...Then" statement, but that implies a loop and I just wish a branch. I need to branch based on the value of $input from the prompt statement. Also need to know if the statements below the prompt statement wait for the user input before continuing.

Options: ReplyQuote
Re: If . . Then statement in Macro Language
Posted by: JujuLand
Date: July 29, 2007 02:41AM

Yes, the statements wait for an input instruction.

To bypass if ... then missing, you cat use a test, like this

if $__answer is the input string

$__answer == "your value" ? make this : make that;

It works ok, but it may be annoying if there is too much things depending of the test result.
To avoid having to test for each line, call function which will do all the things in one case and another function for the other case.

I beg it doesn't make a beautiful code, but it can helps.

But perhaps, Dorian will add this basic test function...

A+


Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:24.0) Gecko/20140105 Ubuntu/12.04 K-Meleon/74.0

Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr





Edited 1 time(s). Last edit at 07/29/2007 02:42AM by JujuLand.

Options: ReplyQuote
Re: If . . Then statement in Macro Language
Posted by: kko
Date: July 30, 2007 07:23PM

Quote
James
I cannot seem to find an "If...Then" statement in the macro language documentation.

We don't have an "If...Then" statement because we don't need it. We have the "? :" operator for that:

<condition>?<statement_conditionTrue>:<statement_conditionFalse>;

The above is a complete "If...Then...Else" statement. An "If...Then" statement would look like this:

<condition>?<statement_conditionTrue>:0;

When the condition is false, nothing (0=zero) is executed.

"? :" (as well as while()) can execute one single statement only. But, of course, this single statement can also be a macro which then executes more than one command:

<condition>?conditionTrue:conditionFalse;

conditionTrue{
...
}
conditionFalse{
...
}


Quote
James
Also need to know if the statements below the prompt statement wait for the user input before continuing.

Yes, of course. Obviously, macro execution cannot go on until the prompt() statement is finished. It's finished when it's returning a value - which is the user's input.

Options: ReplyQuote
Re: If . . Then statement in Macro Language
Posted by: James
Date: July 31, 2007 06:30AM

@ KKO

Thanks. Your explanation much better than wiki documentation. Maybe it should be added to the wiki.

Options: ReplyQuote
Re: If . . Then statement in Macro Language
Posted by: kko
Date: August 01, 2007 08:53PM

I've added it to the Wiki since it's really not obvious for people who are new to the matter.

Simply ask if something is unclear, James.

Options: ReplyQuote
Re: If . . Then statement in Macro Language
Posted by: James
Date: August 03, 2007 06:28AM

KKO, thank you for the new information in the wiki. I have gotten the conditional to work for me now. I am not sure what the amperstand in front of the macro name does but I know it needs it in order to work. I am sure that persons looking for an IF…THEN statement, as I was, will appreciate the direction to look at the conditional .

Now I have a question on forum etiquette. This will be an ongoing project for me so should I continue questions in this thread or start a new thread for each new question?

Just so interested users can see what I am trying to do, I will include the macro code I have written so far. Any constructive suggestions will be appreciated. If anyone knows how to write an internet shortcut or how to find the favorites folder on a given system, I would love to hear from you.

Note that if you try my code, you can open Wordpad and paste from the clipboard to see the output

# K-Meleon Macros
#
# ---------- FavRenAdd
# ---------- K-Meleon Macro Language Rename/Add page to Favorites ---------------
#
# Dependencies : main.kmm, Favorites active
# Resources : -
# Preferences : -
#
# --------------------------------------------------------------------------------
#
_FavRenAdd_RnameTrue{
statusbar("Renaming");
$FavRenAdd_title = substr($FavRenAdd_value,1);
$FavRenAdd_Path = getfolder( RootFolder );
$FavRenAdd_Icon_Lib = $FavRenAdd_Path."\\k-meleon.exe"
$FavRenAdd_OutText = $FavRenAdd_title.\n.$FavRenAdd_CurURL.\n.$FavRenAdd_Icon_Lib.\n.0 ;
setclipboard( $FavRenAdd_OutText );
}

_FavRenAdd_RenameAdd{
$FavRenAdd_CurrTitle = $TITLE;
$FavRenAdd_CurURL = $URL;
statusbar("Rename Add in progress");
$FavRenAdd_value=prompt($FavRenAdd_CurrTitle,"Rename the Favorite Title here");
# cancel from prompt will return a length of zero to which we add one
$FavRenAdd_value = 1.$FavRenAdd_value;
$FavRenAdd_Len=length($FavRenAdd_value);
# if the length is 1 cancelled was pressed on the prompt box
$FavRenAdd_Len == 1 ? STATUSBAR(Rename _ Add CANCELLED):&_FavRenAdd_RnameTrue ;
}

_FavRenAdd_ModMenu{
# add another option to Favorites menu if favorites plugin is active
$kFavorites==true?setmenu(F&avorites,macro,"Rename-Add",_FavRenAdd_RenameAdd,1):0;
}

$OnInit=$OnInit."_FavRenAdd_ModMenu;";
.

Options: ReplyQuote
Re: If . . Then statement in Macro Language
Posted by: kko
Date: August 03, 2007 05:14PM

Quote
James
Now I have a question on forum etiquette. This will be an ongoing project for me so should I continue questions in this thread or start a new thread for each new question?

I guess, that's somewhat a question of taste. Other users can always find what they're looking for through a forum search. Personally, I don't like to create too many new threads - that makes it hard to stay in track of everything. We can continue in this thread. But you can also create new ones if you like that better...


Quote
James
Just so interested users can see what I am trying to do, I will include the macro code I have written so far. Any constructive suggestions will be appreciated. If anyone knows how to write an internet shortcut or how to find the favorites folder on a given system, I would love to hear from you.

You might want to take a look at a macro that I've written two years ago for K-Meleon 0.9. See here.

Note that this macro was written for the old macro system. Simply paste the macros.cfg part into a new kmm file and write a new macro for the menus.cfg part using setmenu(). Place the kmm and the js file in your user macro folder. You also have to add a new global variable to the kmm:

$path=getfolder(UserMacroFolder)."\\";

Options: ReplyQuote
Re: If . . Then statement in Macro Language
Posted by: Popescu
Date: August 11, 2007 05:15AM

Hello. How can i write a macro for K-meleon? Are there somewhere a few examples? Like "hello world" or something like that?

What i want to do is to extract the text from a webpage and paste it in a TXT file.

All Things

Options: ReplyQuote
Re: If . . Then statement in Macro Language
Posted by: Popescu
Date: August 11, 2007 05:17AM

I mean, where do i start? And how? All thinks in the world

Options: ReplyQuote
Re: If . . Then statement in Macro Language
Posted by: JujuLand
Date: August 11, 2007 02:09PM

@ Popescu,

You have some samples on my extensions page. They aren't commented, but some are very easy to do. You can download the source or the setup if you want to install these extensions. In the case you choose setup, the macros are then located in k-meleon macro folder.

A+


Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:24.0) Gecko/20140105 Ubuntu/12.04 K-Meleon/74.0

Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr




Options: ReplyQuote


K-Meleon forum is powered by Phorum.