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:
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 or the /profiles/<your.profile>/macros/ folder. You can open your macros folder by navigating to Configuration > Macros.
Some macros are part of larger extension packages. See the extensions page for more information.
K-Meleon macro modules (.kmm) are text files that contain one or more individual macros. Within a module file, each named section enclosed in {brackets} is a separate macro that can be called from toolbars, menus, other macros, etc. For nearly all places in K-Meleon where a name is required, the name of the individual macro is needed. The one exception is the preferences dialog where module names are used to manage installed modules. Perhaps confusingly both the modules and the individual macros are referred to as "macros."
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:
# Anything on a line starting with "#" is a comment. # Comments do not affect how your code works. # This is our first section of code. Each section works as an individual macro, and # each section can be called by any other macro in any macro file, so choose # descriptive and unique names for them _HelloWorld_BuildMenu{ # You can replace this keyboard accelerator with any shortcut you like: setaccel("CTRL ALT SHIFT H","macros(HelloWorld)"); } # This section is the macro that our keyboard accelerator calls. # Notice that the name is the same. HelloWorld{ alert("Hello world!"); } # --------------------------------------------------------------------- # K-Meleon keeps lists of macros to trigger at different times. # $OnInit is the list of macros that K-Meleon will run before it # processes the user's preferences. This is a good time to create menus # because it won't override any of the user's choices. The # '_HelloWorld_BuildMenu' macro must be in at least one of K-Meleon's # lists for the browser to build the menu. Because our other macro # section is triggered by a command, it does not need to be added. $OnInit=$OnInit."_HelloWorld_BuildMenu;";
You'll notice that the module has two separate macros. First, _HelloWorld_BuildMenu creates an accelerator to trigger a macro. Next, HelloWorld defines that macro.
It can be difficult to remember so 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 a menu option to the browser:
_HelloWorld_BuildMenu{ # The number at the end of the line for menu items can indicate relative # position as below (0 or -1) or it can specify the exact order of several items. setmenu("&View",macro,"Hello World","HelloWorld",0); setaccel("CTRL ALT SHIFT H","macros(HelloWorld)"); } HelloWorld{ alert("Hello world!"); } $OnInit=$OnInit."_HelloWorld_BuildMenu;"; # You likely won't need the line below for simple macros. # $macroModules is a variable where K-Meleon keeps a list of all active # macros. It can be checked by any macro to resolve dependencies. It's # good practice to use it with any macro especially if you share it # with the community. $macroModules=$macroModules."HelloWorld;";
You should now see a menu entry at or near the top of the View menu. 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 the HelloWorld macro. Placing new menus at 0 stacks them at the top of the menu and placing new menus at -1 stacks them at the bottom of the menu.
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{ setmenu("&View",macro,"Large-print","HelloWorld",0); setaccel("CTRL ALT SHIFT H","macros(HelloWorld)"); } HelloWorld{ alert("Large print activated for current page until refreshed."); # This will place custom CSS code into the current page. # "!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, we'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. Now that the macro has a specific function, it doesn't make so much sense to call it HelloWorld. If you wanted to rename parts of the macro it helps to make use of variables. It also helps to use comments not just as messages but to separate your code into chunks. This way if you return the macro after a while you'll still have a decent idea of what you're reading.
# --------------------------------------------------------------------- # Hello World # # UTF-8 K-Meleon Macros # http://kmeleon.sourceforge.net/wiki/MacroLanguage2 # # --------------------------------------------------------------------- $_HelloWorld_menu="&View"; $_HelloWorld_name="Large-print"; $_HelloWorld_macro="HelloWorld"; $_HelloWorld_accel="CTRL ALT SHIFT H"; # --------------------------------------------------------------------- # Macro Sections # --------------------------------------------------------------------- _HelloWorld_BuildMenu{ setmenu($_HelloWorld_menu,macro,$_HelloWorld_name,$_HelloWorld_macro,0); setaccel($_HelloWorld_accel,"macros(HelloWorld)"); } HelloWorld{ alert("Large print activated for current page until refreshed."); injectCSS("html, body, main, p, blockquote, table, tr, td, ol li, ul li { font-size: 18pt !important; }"); } # --------------------------------------------------------------------- # Startup # --------------------------------------------------------------------- $OnInit=$OnInit."_HelloWorld_BuildMenu;"; $macroModules=$macroModules."HelloWorld;";
If you decide to share your macro on the forums, read over the MacroGuidelines especially the section about naming variables.
And congrats on building your first macro!
The above module 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:
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 macro can be shortened down to:
HelloWorld{ alert("Hello world!"); }
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:
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 HelloWorld 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.
Custom Toolbar{ !Button Name{ macros(HelloWorld) Tooltip for button. } }
The first line of this template creates a new toolbar called Custom Toolbar. The next line is the name of the first button. The ! tells K-Meleon to display the name as text. The third line is what launches a macro. You can replace HelloWorld with any macro of your choice. Be sure to use the name of the macro section and not the entire module's file name. Next, there is a tooltip that pops up when your mouse hovers over the icon. You can add custom images below this; refer to the other buttons in your theme for examples or check out the skinning tutorial for more information. Finally, you'll close the button and the toolbar with a pair of curly braces. Save toolbars.cfg and restart K-Meleon to use your macro from the new button.
The documentation for the old macro language and a library of user-submitted legacy macros are archived on the wiki. Even older versions of K-Meleon stored macros within a configuration file called macros.cfg, but as of version 1.0 all functions of macros.cfg were moved into the "main.kmm" module.