K-Meleon

Macros are a unique feature of K-Meleon. You can use them to customize the browser or expand its features. Macros can be activated from toolbars, menus, right-click menus, keyboard shortcuts, events, and even other macros. Macros have several advantages over larger extensions:

  • Macros are easier for end-users to write.
  • They are often a single file.
  • They don't have to be compiled or compressed.
  • They can be opened, read, and modified in any text editor.


Download macros

WARNING: Responsibility for macros lies with their respective owners.

You can find many user-created macros in the extensions forum. There are also many older macros in the Macro Library. You can install a macro by saving it to your K-Meleon > Macros folder. You can open your macros folder by navigating to Configuration > Macros.

Some macros are part of larger packages. These may require an extensions manager. See the extensions page for more information.


Manage macros

  • Open your macro folder to view or edit macros, by going to Edit > Configuration > Macros in the menu. You can edit macros in any text editor.
  • Toggle macros in the preferences by going to Edit > Preferences (F2) >> K-Meleon Plugins > Macro Extension and clicking a macro's name.
  • You can store custom macros in your profile. Create the folder K-Meleon > profiles > macros, copy your custom macros from the default macro folder above, and then paste them into your new profile folder. Any macro in your profile will override the version in the default folder. The profile folder is easier to transport between K-Meleon installations. You can move your profile folder from the old install to the new one, and keep your custom macros.


Writing a simple macro

K-Meleon macros are more approachable than other web browser extension systems. This section will walk you through the steps to build one. Below is the entire code for a simple "Hello world!" macro. To run this in K-Meleon:

  1. Copy the code below into a text editor.
  2. Save it as helloWorld.kmm (note that you may have to set the file type to all files when you save if your editor adds .txt to the end of your file name).
  3. Put the file into your K-Meleon > Macros folder.
  4. Re-start K-Meleon.
  5. Press CTRL+ALT+SHIFT+H or any key combination you define in the macro. And you should see a "Hello world!" alert box appear.
# Anything on a line starting with "#" is a comment.
# Comments do not affect how your code works.

_HelloWorld_BuildMenu{

# You can replace this keyboard accelerator with any shortcut you like:
setaccel("CTRL ALT SHIFT H","macros(HelloWorld)");
}



HelloWorld{
        alert("Hello world!");
}




$OnInit=$OnInit."_HelloWorld_BuildMenu;";
#The name specified below can be used by other macros and config files:
$macroModules=$macroModules."HelloWorld;"; 

You'll notice that the macro has two main sections. First, it builds a menu to access the macro. Next, it defines the function that the macro carries out.

It can be difficult to try to remember many keyboard shortcuts. Most software reminds users of frequent keyboard shortcuts from within its menus. K-Meleon will automatically list your keyboard shortcut if you create a menu option, so let's add an option to the right-click menu of a page:

_HelloWorld_BuildMenu{

# The number at the end of the line for menu items can indicate relative 
# position as below (0, -1) or it can specify the exact order of several items.
$_name="Menu Item";
        setmenu("DocumentSave",macro,$_name,"HelloWorld",-1);
        setmenu("ImageView",macro,$_name,"HelloWorld",-1);
        setmenu("Link",macro,$_name,"HelloWorld",-1);

setaccel("CTRL ALT SHIFT H","macros(HelloWorld)");
}



HelloWorld{
        alert("Hello world!");
}




$OnInit=$OnInit."_HelloWorld_BuildMenu;";
$macroModules=$macroModules."HelloWorld;"; 

You should now see a generic Menu Item (along with your keyboard shortcut) anytime you right-click an empty area of a web page. If it's not visible, close and restart K-Meleon to reload your macro. All the added code does is position a menu item that calls a function.

Next, let's make the above macro into something more useful. Some web pages use tiny fonts, so let's create an accessibility option to give those pages an 18 point font like large-print books:

_HelloWorld_BuildMenu{

$_name="Large-print";
        setmenu("DocumentSave",macro,$_name,"HelloWorld",-1);
        setmenu("ImageView",macro,$_name,"HelloWorld",-1);
        setmenu("Link",macro,$_name,"HelloWorld",-1);

setaccel("CTRL ALT SHIFT H","macros(HelloWorld)");
}



HelloWorld{
        alert("Large print activated for current page until refreshed.");
# "!important" allows this CSS style to override styles on a web page
        injectCSS("html, body, main, p, blockquote, table, tr, td, ol li, ul li {   
        font-size: 18pt !important; }");
}





$OnInit=$OnInit."_HelloWorld_BuildMenu;";
$macroModules=$macroModules."HelloWorld;";

Aside from the name changes, you've only added one line of code to inject some CSS. The line of CSS will increase the font of most parts of a page to 18pt. This will have the most impact on fluid pages like the K-Meleon wiki or Wikipedia.

And congrats on building a macro.


Launching macros with keyboard shortcuts

The above macro is stand-alone. It works without additional files or settings. It's also possible to launch a macro from K-Meleon's keyboard accelerator shortcuts or other macros.

To launch the "HelloWorld" macro above from your keyboard shortcuts:

  1. Make sure that "helloWorld.kmm" is in your K-Meleon > Macros folder.
  2. Click Configuration > Accelerators and your default text editor will open the configuration file for your keyboard accelerator shortcuts.
  3. Type this onto the bottom line of your configurations: CTRL ALT SHIFT H = macros(HelloWorld)
  4. Save the document and re-start K-Meleon.

Custom accelerators allow you to write smaller extensions. Because the config file creates the keyboard shortcut, you don't have to build one in your macro. The HelloWorld macro can be shortened down to:

HelloWorld{
        alert("Hello world!");
}

$macroModules=$macroModules."HelloWorld;";


Launching macros from menus or toolbars

K-Meleon can also launch macros from menus and toolbars. Macros handle many of the default menu options in K-Meleon. To add custom menu options for macros:

  1. Go to Configuration > Menus to open menus.cfg in a text editor.
  2. Create your item using the syntax described in the default config file.
  3. Save menus.cfg and re-start K-Meleon.

For example, the code below would add the HelloWorld macro to K-Meleon's right-click menu on any page. Try adding it and then right-clicking this page:

!Nav {
  HelloWorld=macros(HelloWorld)
}

Nav is the topmost menu section that has navigation options. The exclamation point adds the HellowWorld entry inline rather than replacing items or popping out a submenu. If you want to add an item to the main menu, just choose an area that suits your macro. For example, you could replace Nav with Network above.

You can find more information about custom configurations on the ConfigFiles page. You can find the names of K-Meleon's menus in the default menus.cfg located at K-Meleon/browser/defaults/settings.


Macro references

Legacy Macros

The documentation for the old macro language and a library of user-submitted legacy macros are archived on the wiki.

K-Meleon

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