KMeleonWiki > Resources > MacroLibrary > Groups

Submitted by: jsnj


User Comments?


After viewing MonkeeSage's Session macro, I was inspired to write these. They are a combination
of macros designed to offer most of the features afforded by Groups & Sessions such as:

  • Save all layers as a group
  • Add the URL to a group
  • Add all layers to a group
  • Set a group to automatically open when K-Meleon starts
  • Continue browsing from your last session when K-meleon starts

If you are wary of editing your cfg files and would rather not have to copy & paste the macro code below,
download this file. It contains the default cfg files with the Groups & Session features included.
Extract the contents to your profile directory typically located at the following location on your computer.

C:\Program Files\K-Meleon\Profiles\default\xxxxxxxx.slt\

In Macros:

Replace the # EVENT MACROS section of your macros file with the highlighted text below.

# GROUP MACROS v1.5a (6-22-04)

$kg = "kmeleon.group."
$rl = "ReplaceLayersInWindow?";
$gl = "GetLayersInWindow?";
$fn = "FindNick?";

SaveAsGroup? {
$group = pluginmsgex(layers, $gl,"",STRING);
$name = prompt("Enter a Group Name to save these layers as:", "Group Name?", "");
$name == "" ? "" : setpref(STRING, $kg . $name, $group);
$name == "" ? "" : alert("Type  '" . $name . "'  in the URL Bar and press SHIFT+ENTER to open or ALT+ENTER to open in background.","Group Saved As:  " . $name,INFO);

URLToGroup? {
$name = prompt("Enter Name of Group to add this URL to:", "Group Name?", "");
$name == "" ? "" : getpref(STRING, $kg . $name);
$group = getpref(STRING, $kg . $name);
$name == "" ? "" : setpref(STRING, $kg . $name, $group . $URL . "\t");
$name == "" ? "" : alert("The URL for  '" . $TITLE . "'  has been added to Group: " . $name, "Group:  '" . $name . "'  Updated", INFO);

LayersToGroup? {
$name = prompt("Enter Name of Group to add these layers to:", "Group Name?", "");
$name == "" ? "" : getpref(STRING, $kg . $name); $group = getpref(STRING, $kg . $name);
$curr = pluginmsgex(layers,"GetLayersInWindow?","",STRING);
$name == "" ? "" : setpref(STRING, $kg . $name, $group . $curr);
$name == "" ? "" : alert("Layers added to Group: " . $name, "Group:  '" . $name . "'  Updated", INFO);

setclipboard($URL); id(ID_SELECT_URL?); id(ID_EDIT_PASTE?); id(ID_SELECT_URL?);
alert("No URLs found for Group Name or Folder Nick: '" . $name . "'", "No Group Found"); &ResetURL;
$group = getpref(STRING, $kg . $name); pluginmsg(layers, $rl, $group); &ResetURL;
$curr = pluginmsgex(layers, $gl,"",STRING);
$group = getpref(STRING, $kg . $name); pluginmsg(layers, $rl, $curr . $group); &ResetURL;
setclipboard($name); id(ID_SELECT_URL?); id(ID_EDIT_PASTE?); id(ID_NAV_GO?); &ResetURL;
$curr = pluginmsgex(layers, $gl,"",STRING);
$group = pluginmsgex($plugin, $fn, $name, STRING); pluginmsg(layers, $rl, $curr . $group); &ResetURL;
$plugin="bookmarks"; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? $plugin="hotlist":0;
$group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? macros(NoGroup?) : macros(OpenFolder?);
$plugin="bookmarks"; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? $plugin="hotlist":0;
$group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? macros(NoGroup?) : macros(OpenFolderBg?);
$group = getpref(STRING, $kg . $name) == "" ? macros(ChkFolder?) : macros(Group);
$group = getpref(STRING, $kg . $name) == "" ? macros(ChkFolderBg?) : macros(GroupBg?);
$name = prompt("Enter the Name of the Group to open:", "Group Name?", "");
$name == "" ? "" : macros(OpenGroup?);
$name = prompt("Enter the Name of the Group to open in the background:", "Group Name?", ""); 
$name == "" ? "" : macros(OpenGroupBg?);
$old = getclipboard(); id(ID_SELECT_URL?); id(ID_EDIT_COPY?); $name = getclipboard();
$name == $URL ? macros(PromptGroup?) : macros(OpenGroup?); setclipboard($old);
$old = getclipboard(); id(ID_SELECT_URL?); id(ID_EDIT_COPY?); $name = getclipboard();
$name == $URL ? macros(PromptGroupBg?) : macros(OpenGroupBg?); setclipboard($old);


$layers = "kmeleon.plugins.layers.load";

setpref(BOOL, $sg, "true"); setpref(BOOL, $sl, "true"); setpref(BOOL, $sh, "false");
alert("Your last session pages will open when you start K-Meleon.", "Start Last Session Enabled" , INFO);
&NoGroup?; setpref(STRING, $sn, $oldname); &DefineStartupGroup?;
setpref(BOOL, $sg, "true"); setpref(BOOL, $sh, "false"); setpref(BOOL, $sl, "false");
alert("The Group or Folder with Nick:  '" . $name . "'  will open when you start K-Meleon.", "Startup Group Enabled - " . $name, INFO);
$last = confirm( "There is a Group or Folder with the Nick:  '" . $name . "'.  Do you want it to be the Startup Group instead of starting with your last session?", Startup Group?, YESNO, QUESTION );
$last == "YES" ? macros(AlertGroup?) : macros(AlertLast?);
$plugin="bookmarks"; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? $plugin="hotlist":0;
$group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? macros(AlertLast?) : macros(GroupLast?);
$group = getpref(STRING, $kg . $name) == "" ? macros(ChkFolderLast?): macros(GroupLast?);
$plugin="bookmarks"; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? $plugin="hotlist":0;
$group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? macros(NoStart?) : macros(AlertGroup?);
$oldclip = getclipboard(); setclipboard($name);
$group = getpref(STRING, $kg . $name) == "" ? macros(FolderCheck?) : macros(AlertGroup?);
$oldname = getpref(STRING, $sn);
$name = prompt("Enter Group Name or Folder Nick. Type 'last' to start with last session.", "Startup Group Name?", $oldname);
$name == "" ? "" : setpref(STRING, $sn, $name);
$name  "" ? "" : getpref(STRING, $sn)  "last" ? macros(ChkGroupLast?) : macros(StartGroup?);

setpref(BOOL, $sg, "false"); 
$start = confirm( "Startup Group Disabled. Click 'YES' to start with your Home Page. 'NO' to start with a blank page.", "Home Page Start?", YESNO, QUESTION ) == "YES" ? setpref(BOOL, $sh, true) : setpref(BOOL, $sh, false);


alert("The layers plugin must be enabled to save and open your last session pages. If this is your first session using the Groups & Session macros and the layers plugin is enabled, then from now on your last session pages will be saved.", "Last Session Not Found");
$group = getpref(STRING, $kl); pluginmsg(layers, $rl, $group);
getpref(STRING, $kl) == "" ? macros(NoLast?) : macros(OpenLast?);
getpref(STRING, $kg . $name) == "" ? macros(ChkFolder?) : macros(Group);
getpref(BOOL, $sl) == "true" ? macros(CheckLast?) : macros(FindGroup?);
getpref(BOOL, $sl) == "true" ? macros(NoLast?) : macros(ChkFolder?);
getpref(BOOL, $layers) == "true" ? macros(StartLayers?) : macros(StartWindows?);
$oldclip = getclipboard(); $name = getpref(STRING, $sn);
id(ID_SELECT_URL?); id(ID_EDIT_COPY?); $theurl = getclipboard();
$theurl == "about:blank" ? macros(LayersCheck?):0;
setclipboard($oldclip); $loaded="";

$name = getpref(STRING, $sn); getpref(BOOL, $sg) == "true" ? macros(LayersCheck?) : id(ID_NAV_HOME?);

$group = pluginmsgex(layers,$gl,"",STRING); setpref(STRING, $gt, $group);
$closed = getpref(STRING, $gt); $group = pluginmsgex(layers,$gl,"",STRING);
$group  $closed ? 0 : $group =""; $group  "" ? pluginmsg(layers, $rl, $closed) : 0 ;


$group = getpref(STRING, $gt); setpref(STRING, $kl, $group);
getpref(BOOL, $layers) == "true" ? setpref(STRING, $og, "layers(ReplaceLayersInWindow?)"):0;
getpref(BOOL, $sg) == "true" ? $loaded="GroupStart?":0;

$URL=""; $URL == "about:blank" ? id(ID_SELECT_URL?):0;
$loaded == "" ? 0 : macros($loaded); &buttonSync; &GetSetTemp?;

$group = getpref(STRING, $gt); setpref(STRING, $kl, $group);

In Menus:

Copy & paste the text highlighted in gray above the Main section in your menus file:

%ifplugin layers
macros(CheckLast?, Open Last Session\tCtrl+Alt+L)
macros(OpenClosed?, Open Last Closed\tCtrl+Alt+Z)
macros(CheckURL, Open Group...\tShift+Enter)
macros(CheckURLBg?, Open Group in Background...\tAlt+Enter)
macros(SaveAsGroup?, Save As Group...\tCtrl+Alt+G)
macros(URLToGroup?, Add URL To Group...\tAlt+U)
macros(LayersToGroup?, Add Layers To Group...\tAlt+L)
macros(DefineStartupGroup?, Define Startup Group...\tAlt+S)
macros(DisableStartupGroup?, Disable Startup Group\tAlt+X)
%ifplugin layers
%ifplugin history

And then within the Main section, copy & paste the text highlighted in gray:

Main {

%ifplugin bookmarks
%ifplugin favorites
%ifplugin hotlist


%ifplugin macros

%ifplugin layers


%ifplugin winamp

%ifplugin weasel

In Accelerators:

Copy & paste the text highlighted in gray:

ALT S = macros(DefineStartupGroup?)
ALT X = macros(DisableStartupGroup?)

And in the layers section:

%ifplugin layers

CTRL ALT L = macros(CheckLast?)
CTRL ALT Z = macros(OpenClosed?)
CTRL ALT G = macros(SaveAsGroup?)
ALT U = macros(URLToGroup?)
ALT L = macros(LayersToGroup?)
SHIFT VK_RETURN = macros(CheckURL)
ALT VK_RETURN = macros(CheckURLBg?)

CTRL VK_TAB = layers(Next)
CTRL SHIFT VK_TAB = layers(Prev)
CTRL T = layers(Open)
CTRL N = layers(OpenWindow)
CTRL VK_F4 = layers(Close)
CTRL VK_NEXT = layers(Next)
CTRL VK_PRIOR = layers(Prev)
CTRL W = layers(Close)
CTRL SHIFT W = layers(CloseWindow)
MButton = layers(OpenLink)
CTRL LButton = layers(OpenLink)
CTRL RButton = layers(OpenLinkBg)

In Toolbars:

Copy & paste the text highlighted in gray:

Home {

  Home Page / Startup Group



v1.5a (June. 22nd '04)
1. SHIFT+ENTER and ALT+ENTER now serve as open group prompts if nothing has been entered into the URL bar.
2. This version includes changes to the menus & accelerators as well as macros.

v1.4a (June. 22nd '04)
1. As per request, the DisableStartupGroup macro now gives the option to start with a blank page.
2. Further testing seems to reveal that the GetSetTemp macro doesn't function in the OnOpenWindow event macro
probably due to a timing conflict, so that's been removed.
3. Same goes for the Last Session tweak of v1.3, so that's been reverted.

v1.3a (June. 3rd '04)
1. Tweaked the Last Session feature to ignore a blank page as the last session.
2. Removed the OnCloseWindow macro until Bug 692 is fixed. As a result:
3. The Open Last Closed (Undo Close Tab) feature has been altered since the GetSetClosed macro is no longer needed.
It should also work properly now. The last version required clicking it twice.

v1.2a (May. 4th '04)
Fixed a bug with the 'Open Last Closed' macro which prevented it from reopening the closed layer if that was the only open layer
at the time of closing. This fix eliminates the need for the following pref and macro strings:

user_pref("kmeleon.plugins.layers.count", );

v1.1 (Apr. 5th '04)
1. Added a ResetURL macro. As a result:

a)The URL is now restored to the URL Bar when opening groups. That was a consistent cosmetic bug in previous versions
particularly when opening groups in the background.
b)The URL and focus are automatically returned to the URL Bar for immediate retyping after the 'No Group Found' alert macro.

2. The 'Define Startup Group' macro is automatically restarted for retyping if there is No Group Found.
3. Fixed a bug with the 'Home' macro. The variable $name needed to be defined for the recognition of Folder Groups.
4. Version 1.0's refinement of 'Open Last Closed' prevented restoration after 'Close All Layers' & 'Close All Other Layers'. That's been fixed.

v1.0 (Mar. 28th '04)
1.The 'DefineStartupGroup' macros now recognize if a Group or Folder has the nickname 'last' and therefore gives the option
to use that as the Startup Group or to start with your last session. As a result, the pref "kmeleon.general.startLastSession" has been reinstated.
2. Minor adjustment to the 'Open Last Closed' macro. It won't reload your current pages unless it finds any closed pages to reopen.
Previous version reloaded the current pages regardless.
3. Eliminated the 'OpenStart' macro since it was a copy of the macro 'Group'.

v0.95 (Mar. 19th '04) - Corrected an oversight which created a bug that prevented opening Folder Groups in the background.
The variable '$group' needed to be defined in the OpenFolderBg macro.

v0.9 (Mar. 18th '04)
1. Added an 'Open Last Closed' feature (a.k.a. Undo Close Tab) which can also reopen all layers closed by the 'Close All Layers' & 'Close All Other Layers' commands.

*The closed layers will not be recalled after you reload or load another page.

2. Cleaned up the macro script in some areas by eliminating unnecessary conditional strings.
3. (minor) Changed the wording in some of the alerts and menus.

v0.85 (Jan. 12th '04) - I forgot to include $loaded=""; below # LAST SESSION & STARTUP GROUP MACROS in the Jan. 3rd update.

v0.8 (Jan. 3rd '04)
1. Hotlist plugin users no longer have to disable the bookmarks plugin for their hotlist folder nicks to be recognized.
2. Added the OnQuit macro to ensure the last session is saved in the unforeseen event of a crash at startup.
3. (minor) The DefineStartupGroup prompt now displays the currently set startup group name.

v0.7 (Dec. 21st '03)
1. SHIFT+ENTER (OpenGroup) & ALT+ENTER (OpenGroupBg) now recognize Folder Groups.
2. Added macros(Home) to be used in place of ID_NAV_HOME in toolbars. It opens your Startup Group instead of your Home Page if the Startup Group is enabled.
3. Corrected a silly mistake by changing OnNewWindow to OnOpenWindow.
4. Changed the menu name from Groups to G&roups to allow ALT+R to be used as its main menu accelerator for users who disable the rebar plugin.
5. Cleaned up the macro script in some areas eliminating the following prefs that the previous Group & Session macros set:

v0.6 (Dec. 13th '03)
1. Users who have the layers plugin disabled can now use the Define Startup & Disable Startup Group macros with the advent of nicknames for bookmark & hotlist folders in KM v0.8.1.
2. Folder Groups can now be the Startup Group.
3. Improvements to the Last Session function. All open layers are recorded at each event instead of only at OnLoad.
4. Your Last Session Before Exit will now be saved even if the browser crashes.
5. Changed the Save As Group accelerator from ALT+G to CTRL+ALT+G so as not to conflict with the coded Go menu keyboard shortcut.

*Using ID_APP_EXIT (Ctrl+Alt+F4) to close the browser may produce a Windows error message on exit because of a bug with the layers & macros plugins.
Your last session will still be saved. It's more of an annoying cosmetic bug than a functional bug. Exiting with ID_FILE_CLOSE (Windows title bar upper right-corner X) works fine.

v0.5 (Nov.23rd '03) - (minor) Added the page title to the 'Add URL To Group' macro confirmation alert.

v0.4 (Nov. 4th '03) - Changed the "Open Group In Background" accelerator from ALT+/ to ALT+ENTER to work with international keyboards.

v0.3 (Nov. 1st '03)
1. Now recognizes when the defined startup group doesn't exist.
2. I finally realize why setting & resetting the clipboard is necessary, so that's been added to the applicable sections.

v0.2 (Oct. 31st '03) - Fixed the Define Startup Group problem by changing the DefineStartupGroup & StartupGroup macros.

User Comments:

by: Sebastian(Jun 23st, '04)

there is a bug. If the url bar is empty KM shows the content of the clipboard and not the GroupPrompt? solution: NoGroup?{ macros(PromptGroup?) }

by: Sebastian(Jun 21st, '04)
wow - that is really good, good work
To do List:

  • show saved groups in a list, by clicking on the groupname it opens;
  • Delete a group
  • after disabling startup group, the startpage is reset to the last used startpage
    maybe about:blank, when clicked that K-Meleon shall open only a blank page and not the startpage.

by: jsnj(Jun 21st, '04)
Thanks. As for your todo list. I would if I could. :-). Unfortunately the macro plugin can only write to the prefs file, not the cfg files.
So I'm guessing an actual plugin would be needed for a groups list. Also, there's no way to delete a pref(the saved groups)
while KM is running. I was originally thinking of resetting the last used start page, but trying not to bloat the script any more than it is,
I decided against it assuming those who start KM with a blank page would probably never want to start with a group of pages.
I may change it though I'd probably have to add another pref.

by: Sebastian(Jun 22nd, '04)
Information for jsnj

in macro:
$name = prompt("Enter a Group Name to open:", "Which Group shall I open?", "");
in menus:
macros(OpenGroupPrompt?, Open a Group\tundefined)

K-Meleon crashes sometimes on exiting. I think the function onQuit() is the Problem.

by: jsnj(Jun 22nd, '04)
Opening groups from the URL bar with SHIFT+ENTER and ALT+ENTER(in background) eliminates the need for a prompt.
If I can find a way to list all the saved groups in the prompt dialogue then I may add it.
In the meantime if you want a prompt function anyway add the following in macros:

OpenGroupPrompt? {
$name = prompt("Enter the Name of the Group to open:", "Group Name?", "");
$name  "" ? "" : $group = getpref(STRING, $kg . $name)  "" ? macros(ChkFolder?) : macros(Group); 

As for crashing on exit, I've had no reports of that other than Bug 692 which was remedied with v1.3.
I've also tried the Groups macros in K-Meleon version M1.7 test build with no crashes.
If you want, you can try it without the OnQuit macro. You should still get your last session.
It's just an added precautionary measure. But I've never seen crashes as a result of that.
Also, please add your comments to this section of the page, not at the top, or in forums in the development section is easiest.


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