K-Meleon

Important - Work in Progress

K-Meleon Macro Language wiki page reorganization project

This page is my effort to better organize the page so it can display the new and expanded statements coming with the 1.5 version.

It is incomplete.

 
  Many items are shown only with placeholders.  It can and will change from
  time to time.  I will set up a thread in the general forum for discussion
  and comment.

                                                     JamesD

K-Meleon Macro Language


Contents


See also:


Comments

A line starting with # is a comment and is ignored.

# this is a comment


Variables and Macros

Variables are not declared explicitly, but must have a name starting with a dollar sign. A variable can either be global, accessible from any macro, or local to a specific macro. Before a variable can be used in an expression, it must be assigned a value. Integer and string values are available.

    $x = 0; 
    $y = "A text string";


Macro declarations consist of a macro name followed by a compound of statements enclosed in curly braces to execute for that macro. An optional assignment of a string value to 'menu' can be used to set the text shown when the macro is used in menus.

    example { 
        menu = "Menu text"; 
        $x = 0; 
    }


Expressions

The following operators are available:

Operator Meaning Sample Statement Integer Result
= assignement $x = 7; $x = 7
. string concatenation $x = 7 . 3; $x = 73
+ integer addition $x = 7 + 3; $x = 10
- integer subtraction $x = 7 - 3; $x = 4
* integer multiplication $x = 7 * 3; $x = 21
/ integer division $x = 7 / 3; $x = 2
% integer remainder $x = 7 % 3; $x = 1
== equality $x = 7 == 3; $x = 0
!= unequality $x = 7 != 3; $x = 1
<, <=, >, >= string comparison $x = 10 < 2 $x = 1
<, <=, >, >= integer comparison $x = +10 > +2 $x = 1
? : conditional expression $x = $y==1 ? 2:3; $x = 2 if y equals 1, $x = 3 otherwise

Parentheses can be used to alter the evaluation order. By default, addition and subtraction have higher precedence than multiplication, division and remainder operations.

When needed, a variable is automatically converted from a string to an integer, or vice versa.

    $x = 1 + "2";                       $x = 3  
    $y = "The value of x is " . x;      $y = "The value of x is 3"


Special Strings

Strings should be enclosed in double quotes although not required unless the string contains operators. A backslash is used to escape special characters:

\\ backslash (\)
\n newline character
\t tabulator
\" quotation mark (")

The string values "true" and "false" are recognized as boolean values and can be used in place of a conditional expression.

    $z = "false";
    $z ? $x = 1 : $x = 0;               $x = 0
    $z = "true";
    $z ? $x = 1 : $x = 0;               $x = 1


Special Global Variables

There is a number of predefined global variables to let K-Meleon macros access some global state information.

$ARG Argument given from caller plugin (not from caller macro). Since 0.9
$CHARSET Character encoding used for the current page. Since 1.0.
$FrameURL URL for the current frame. Since 0.8.2
$ImageURL URL for the current image. Since 0.8
$LinkURL URL for the current link. Since 0.8
$SelectedText Selected text in the current page. Since 1.0.
$TextZoom Text zoom factor for the current page. Since 1.0.
$TITLE Title for the current page. Since 0.9
$URL URL for the current page. Since 0.7
$URLBAR Contents of the URL bar. Since 1.0.


Events

    OnActivateWindow
    OnCloseGroup
    OnCloseWindow
    OnInit
    OnLoad
    OnOpenWindow
    OnQuit
    OnSetup
    OnStartup
    OnWMAppExit


Statements

Statements should be finished by a semicolon. Statements may not span several lines!

    THIS CODE IS INVALID
    $error = 1 +
        1;

Several statements can be lined up on the same line with a semicolon in between.

    $x = 0; $y = "A text string";


Conditional statements

The conditional expression operator (? :) can be used to execute a single statement depending on a certain condition.

A complete "If ... Then ... Else ..." statement would look like this:

    CONDITION ? STATEMENT_CONDITION_TRUE : STATEMENT_CONDITION_FALSE;

A simple "If ... Then ..." statement would look like this:

    CONDITION ? STATEMENT_CONDITION_TRUE : 0;

In the example above, nothing (0 = zero) is executed when the condition is false.

To execute multiple statements depending on a certain condition, these have to be encapsulated in helper macros:

    CONDITION ? &ConditionTrue : &ConditionFalse;

    ConditionTrue {
        ...
    }
    ConditionFalse {
        ...
    }


Documents


Document Manipulation

forcecharset() Since version 0.9
injectCSS() Since version 1.0
injectJS() Since version 1.0


Opening Documents

open() Since version 0.4
opennew() Since version 0.4
openbg() Since version 0.4
opentab() Since version 1.5
openbgtab() Since version 1.5

String Handling


General

index() Since version 0.7
length() Since version 0.7
substr Since version 0.7


Substitution

_() Since version 1.0
gensub() Since version 0.7
gsub() Since version 0.7
sub() Since version 0.7


URLs

basename() Since version 0.7
dirname() Since version 0.7
hostname() Since version 0.7
urlencode() Since version 1.0


Iteration

while() Since version 1.0

                                1.5        (syntax was extended to support execution of)         
                                                                (multiple statements)


Interfaces to


The User


Simple Dialogs / Modal Windows

    alert( MESSAGE [, TITLE [, ICON]] );       Since version 0.8

Shows a messagebox.
ICON = EXCLAIM | INFO | STOP | QUESTION

    $RESULT = confirm( MESSAGE [, TITLE [, BUTTONS [, ICON]]] );      Since version 0.9

Shows a messagebox and asks for confirmation.
BUTTONS = RETRYCANCEL | YESNO | YESNOCANCEL | ABORTRETRYIGNORE
ICON = EXCLAIM | INFO | STOP | QUESTION
RESULT = OK | YES | NO |ABORT | RETRY | IGNORE | 0

    $VALUE = prompt( MESSAGE [, TITLE [, DEFAULT_STRING]] );     Since version 0.7

Shows a modal 'prompt' dialog and returns a string value.


Setting Accelerator Key Definitions

setaccel() Since version 1.1


Menus

setmenu() Since version 1.1
menuchecked Since version 1.1
menugrayed Since version 1.1
rebuildmenu() Since version 1.1


The Operating System

exec() Since version 0.6

      
                                      1.0        (expands environment variables)

promptforfile() Since version 1.0
promptforfolder() Since version 1.0
readfile() Since version 1.0
readreg() Since version 1.0


The Browser

arg() Since version 0.9
getfolder() Since version 1.1
id() Since version 0.7
macros() Since version 0.7

                      version 1.1        (syntax extended to support execution of)
                                              (multiple macros)


The Browser Preference System

delpref() Since version 0.9
getpref() Since version 0.7
setpref() Since version 0.6
togglepref() Since version 0.6

The K-Meleon Plugins

plugin() Since version 0.7
pluginmsg() Since version 0.7
pluginmsgex() Since version 0.7

The Clipboard

    $TEXT = getclipboard();       Since version 0.7

Gets data from the clipboard.

    setclipboard( TEXT );     Since version 0.7

Sets data to the clipboard.

The Statusbar

    statusbar( TEXT );      Since version 0.7

Shows the message text on the status bar.

Alphabetical Index

  
 * $ARG                         
 * $CHARSET                        
 * $FrameURL                                
 * $ImageURL                        
 * $LinkURL                        
 * $SelectedText        
 * $TextZoom        
 * $TITLE                        
 * $URL                        
 * $URLBAR
 * _()                        
 * alert()
 * arg()
 * basename()                
 * confirm()
 * delpref()                        
 * dirname()                
 * exec()
 * forcecharset()        
 * gensub()
 * getclipboard()        
 * getfolder()                
 * getpref()        
 * gsub()
 * hostname()
 * id()        
 * index()        
 * injectCSS()        
 * injectJS()        
 * length()
 * macros()        
 * menu                                                  0.4        depreciated
 * menuchecked        
 * menugrayed
 * open()        
 * openbg() 
 * openbgtab() 
 * opennew() 
 * opentab() 
 * plugin()
 * pluginmsg()
 * pluginmsgex()
 * prompt()                
 * promptforfile()        
 * promptforfolder()        
 * readfile()
 * readreg()        
 * rebuildmenu()
 * setaccel()          
 * setcheck()                                              0.9        depreciated
 * setclipboard()        
 * setmenu()        
 * setpref()        
 * statusbar()        
 * sub()        
 * substr()
 * togglepref()
 * urlencode()                
 * while()        
K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.