K-Meleon
KMeleonWiki > Resources > MacroLibrary > MacroLibrary2 > Groups
Submitted by: jsnj
Note: this macro requires the deprecated layers Kplugin for pseudo-tabs; layers are deprecated. The latest official versions of K-Meleon and all active development natively support true tabs.
Notes:
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:
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\
Replace the # EVENT MACROS section of your macros file with the text below.
# GROUP MACROS v1.6a (7-18-04) $kg = "kmeleon.group." $rl = "ReplaceLayersInWindow"; $gl = "GetLayersInWindow"; $fn = "FindNick"; $gn = "kmeleon.groupnames"; ReadNames{ $names = getpref(STRING, $gn); } SaveAsGroup{ &ReadNames; $names == "" ? $names = "\n" :0; $group = pluginmsgex(layers, $gl,"",STRING); $name = prompt("Enter a Group Name to save these layers as:", "Group Name?", ""); $checkname = "\n" . $name . "\n"; $name == "" ? "" : $exists = index($names, $checkname); $name == "" ? "" : $exists != -1 ? macros(ConfirmGroup) : macros(SaveGroup); } ConfirmGroup{ confirm("Group Name exists. Overwrite?", "Group Name '" . $name . "' Found", YESNO, QUESTION)=="YES" ? setpref(STRING, $kg . $name, $group) : macros(SaveAsGroup); } SaveGroup{ setpref(STRING, $gn, $names . $name . "\n"); setpref(STRING, $kg . $name, $group); 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); } SavedGroups{ &ReadNames; $names == "" ? $var = "Folder" : $var = "Group or Folder"; $names == "" ? $names = "No Group Names Found" ."\n" :0; $open = confirm($names . "\n\nOpen a " . $var . " now? Click 'NO' to open in background.", "Saved Groups", YESNOCANCEL); $open == "CANCEL" ? "" :0; $open == "YES" ? macros(PromptGroup):0; $open == "NO" ? macros(PromptGroupBg):0; } URLToGroup{ $name = prompt("Enter a Group Name to add this URL to:", "Group Name?", ""); $name == "" ? "" : getpref(STRING, $kg . $name); $group = getpref(STRING, $kg . $name); $name == "" ? "" : $group == "" ? macros(NoGroup) : macros(AddURL); } AddURL{ setpref(STRING, $kg . $name, $group . $URL . "\t"); alert("The URL for '" . $TITLE . "' has been added to Group: " . $name, "Group: '" . $name . "' Updated", INFO); } LayersToGroup { $name = prompt("Enter a Group Name to add these layers to", "Group Name?", ""); $name == "" ? "" : getpref(STRING, $kg . $name); $group = getpref(STRING, $kg . $name); $name == "" ? "" : $group == "" ? macros(NoGroup) : macros(AddLayers); } AddLayers{ $curr = pluginmsgex(layers,"GetLayersInWindow","",STRING); setpref(STRING, $kg . $name, $group . $curr); alert("Layers added to Group: " . $name, "Group: '" . $name . "' Updated", INFO); } ResetURL{ setclipboard($URL); id(ID_SELECT_URL); id(ID_EDIT_PASTE); id(ID_SELECT_URL); } NoGroup{ alert("No URLs found for Group Name: '" . $name . "'", "No Group Found"); &ResetURL; } Group{ $group = getpref(STRING, $kg . $name); pluginmsg(layers, $rl, $group); &ResetURL; } GroupBg{ $curr = pluginmsgex(layers, $gl,"",STRING); $group = getpref(STRING, $kg . $name); pluginmsg(layers, $rl, $curr . $group); &ResetURL; } OpenFolder{ setclipboard($name); id(ID_SELECT_URL); id(ID_EDIT_PASTE); id(ID_NAV_GO); &ResetURL; } OpenFolderBg{ $curr = pluginmsgex(layers, $gl,"",STRING); $group = pluginmsgex($plugin, $fn, $name, STRING); pluginmsg(layers, $rl, $curr . $group); &ResetURL; } ChkFolder{ $plugin="bookmarks"; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? $plugin="hotlist":0; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? macros(NoGroup) : macros(OpenFolder); } ChkFolderBg{ $plugin="bookmarks"; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? $plugin="hotlist":0; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? macros(NoGroup) : macros(OpenFolderBg); } OpenGroup{ $group = getpref(STRING, $kg . $name) == "" ? macros(ChkFolder) : macros(Group); } OpenGroupBg{ $group = getpref(STRING, $kg . $name) == "" ? macros(ChkFolderBg) : macros(GroupBg); } PromptGroup{ $name = prompt("Enter the Name of the Group to open:", "Group Name?", ""); $name == "" ? "" : macros(OpenGroup); } PromptGroupBg{ $name = prompt("Enter the Name of the Group to open in the background:", "Group Name?", ""); $name == "" ? "" : macros(OpenGroupBg); } CheckURL{ $old = getclipboard(); setclipboard(); id(ID_SELECT_URL); id(ID_EDIT_COPY); $name = getclipboard(); $name == "" ? $name = $URL : ""; $name == $URL ? macros(PromptGroup) : macros(OpenGroup); setclipboard($old); } CheckURLBg{ $old = getclipboard(); setclipboard(); id(ID_SELECT_URL); id(ID_EDIT_COPY); $name = getclipboard(); $name == "" ? $name = $URL : ""; $name == $URL ? macros(PromptGroupBg) : macros(OpenGroupBg); setclipboard($old); } # LAST SESSION & STARTUP GROUP MACROS v1.6a (7-18-04) $loaded=""; $sg="kmeleon.general.startGroup"; $sh="kmeleon.general.startHome"; $sn="kmeleon.general.startGroupName"; $sl="kmeleon.general.startLastSession" $og="kmeleon.general.opengroup"; $gt="kmeleon.grouptemp"; $kl="kmeleon.grouplast"; $layers = "kmeleon.plugins.layers.load"; AlertLast{ 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); } NoStart{ &NoGroup; setpref(STRING, $sn, $oldname); &DefineStartupGroup; } AlertGroup{ 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); } GroupLast{ $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); } ChkFolderLast{ $plugin="bookmarks"; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? $plugin="hotlist":0; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? macros(AlertLast) : macros(GroupLast); } ChkGroupLast{ $group = getpref(STRING, $kg . $name) == "" ? macros(ChkFolderLast): macros(GroupLast); } FolderCheck{ $plugin="bookmarks"; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? $plugin="hotlist":0; $group = pluginmsgex($plugin, $fn, $name, STRING) == "" ? macros(NoStart) : macros(AlertGroup); } StartGroup{ $oldclip = getclipboard(); setclipboard($name); $group = getpref(STRING, $kg . $name) == "" ? macros(FolderCheck) : macros(AlertGroup); setclipboard($oldclip); } DefineStartupGroup{ $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); } DisableStartupGroup{ 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); } NoLast{ 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"); } OpenLast{ $group = getpref(STRING, $kl); pluginmsg(layers, $rl, $group); } CheckLast{ getpref(STRING, $kl) == "" ? macros(NoLast) : macros(OpenLast); } FindGroup{ getpref(STRING, $kg . $name) == "" ? macros(ChkFolder) : macros(Group); } StartLayers{ getpref(BOOL, $sl) == "true" ? macros(CheckLast) : macros(FindGroup); } StartWindows{ setpref(STRING, $og, "ID_OPEN_LINK|ID_OPEN_LINK_IN_BACKGROUND"); getpref(BOOL, $sl) == "true" ? macros(NoLast) : macros(ChkFolder); setpref(STRING, $og, "ID_OPEN_LINK_IN_NEW_WINDOW|ID_OPEN_LINK_IN_BACKGROUND"); } LayersCheck{ getpref(BOOL, $layers) == "true" ? macros(StartLayers) : macros(StartWindows); } GroupStart{ $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=""; } Home{ $name = getpref(STRING, $sn); getpref(BOOL, $sg) == "true" ? macros(LayersCheck) : id(ID_NAV_HOME); } GetSetTemp{ $group = pluginmsgex(layers,$gl,"",STRING); setpref(STRING, $gt, $group); } OpenClosed{ $closed = getpref(STRING, $gt); $group = pluginmsgex(layers,$gl,"",STRING); $group == $closed ? 0 : $group =""; $group == "" ? pluginmsg(layers, $rl, $closed) : 0 ; } # EVENT MACROS w/LAST SESSION & STARTUP GROUP SUPPORT v1.6a (7-18-04) OnStartup{ $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; } OnLoad{ $URL=""; $URL == "about:blank" ? id(ID_SELECT_URL):0; $loaded == "" ? 0 : macros($loaded); &buttonSync; &GetSetTemp; } OnQuit{ $group = getpref(STRING, $gt); setpref(STRING, $kl, $group); }
Copy & paste above the Main section in your menus file:
G&roups{ %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(SavedGroups, Saved Groups...\tAlt+Shift+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) - %endif macros(DefineStartupGroup, Define Startup Group...\tAlt+S) macros(DisableStartupGroup, Disable Startup Group\tAlt+X) %ifplugin layers - layers() %else %ifplugin history history() %endif %endif }
And then within the Main section, copy & paste the highlighted text:
Main { :&File :&Edit :&View :&Go %ifplugin bookmarks :&Bookmarks %endif %ifplugin favorites :F&avorites %endif %ifplugin hotlist :Ho&tlist %endif %ifplugin macros :G&roups %endif %ifplugin layers :&Layers %endif %ifplugin winamp :Winamp %endif %ifplugin weasel :EMail %endif :&Help bmpmenu() }
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) SHIFT VK_RETURN = macros(CheckURL) ALT VK_RETURN = macros(CheckURLBg) ALT SHIFT VK_RETURN = macros(SavedGroups) CTRL ALT G = macros(SaveAsGroup) ALT U = macros(URLToGroup) ALT L = macros(LayersToGroup) 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) %else
Copy & paste the highlighted text:
Home { macros(Home) Home Page / Startup Group toolhot.bmp[4] toolcold.bmp[4] tooldead.bmp[4] }
v1.6a (July 18th '04)
1. Added a 'Saved Groups' feature with help from Sebastian.
It shows a list of all the saved groups with the option given to then open one of them. As a result:
2. Adjustments were made to the SaveAsGroup, URLToGroup, LayersToGroup, & NoGroup macros.
*If updating from previous version, open your groups and resave them to record their names in the new Saved Groups list.
3. This version includes changes to the menus & accelerators as well as macros.
v1.55a (June. 23rd '04)
Fixed a bug related to the prompt which occured when the URL bar was empty.
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:
v1.1 (Apr. 5th '04)
1. Added a ResetURL macro. As a result:
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:
"kmeleon.general.groupFound"
"kmeleon.general.folderFound"
"kmeleon.general.startLastSession"
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.
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.
Have also a look in the development forum, there is a thread.
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.
by: Sebastian(Jun 22nd, '04)
Information for jsnj
Additions:
in macro:
OpenGroupPrompt{ $name = prompt("Enter a Group Name to open:", "Which Group shall I open?", ""); macros(Group); }
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 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 21st, '04)
wow - that is really good, good work
To do List: