KMeleonWiki > Resources > MacroLibrary > KmmShortcut

Submitted by: kko


This macro introduces Internet Explorer's "Create Shortcut" feature into K-Meleon. It empowers you, to send the URL of the current page or frame or of a link quickly to your desktop as an Internet Shortcut to revisit it later. This is a valuable functionality when you find an interesting page that you don't want to read instantly, but in the near future. Or when you want to save an email address from a link to add it to your address book later. The shortcut on your desktop will remind you, whereas a bookmark is quickly forgotten...

Windows Script Host 1.0 (or better) required!

WSH is part of Microsoft Internet Explorer 5.0 and newer. Latest version of WSH is available in the Download Section of Microsoft's Scripting Homepage.

As an alternative to this very simple Windows Scripting solution (Shortcut.js), Alain Aupeix offers a compiled executable (WebShortcut.exe) with extended functionality. Have a look at his Page du K-Meleon.


Localization support added.
Updated to the K-Meleon 1.1 macro system.
Minor macro update. Link to Alain's website added.
Shortcut.js updated to version 1.1 to take care of wyciwyg:// URLs. Macros improved to properly work on pages that have no title.
Macros improved. LinkToDesktop now uses the link's text as shortcut name. FrameToDesktop now uses the frame's title as shortcut name.

Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder
(Edit > Configuration > Macros) and create the following text files:


# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ---------- Send URLs to Windows desktop as Internet Shortcut (*.url) ---------------------------------------------
# Dependencies : main.kmm (JS)
# Resources    : Shortcut.js
# Preferences  : -
# ------------------------------------------------------------------------------------------------------------------

$_Shortcut_URL=$LinkURL;  $__temp=$TITLE==$URL?"":$TITLE; $JS_doitLink="top.document.title=a[j].textContent;j=a.length"; &JS_hndlLink;
$_Shortcut_Title=$TITLE==$URL?"":gsub("\"","'",$TITLE); injectJS("top.document.title='".$__temp."'");
$_Shortcut_URL=$FrameURL; $__temp=$TITLE==$URL?"":$TITLE; $JS_doit="top.document.title=title"; &JS_hndlDoc;
$_Shortcut_Title=$TITLE==$URL?"":gsub("\"","'",$TITLE); injectJS("top.document.title='".$__temp."'");

# ----- PRIVATE


exec("wscript.exe \"".$_Shortcut_Path."\" \""._("New Internet Shortcut")."\" \""._("New Contact")."\" \"".$_Shortcut_URL."\" \"".$_Shortcut_Title."\"");

$__c="C&reate Shortcut";

# Shortcut.js is supposed to be located in the same folder as Shortcut.kmm (this file).
# If it isn't, Windows Script Host will notify the user.

# ------------------------------------------------------------------------------------------------------------------


/* Shortcut.js by kko, version 1.2

   This script is a helper application for the K-Meleon Macro Module Shortcut.kmm that
   enables you to send the URL of a page, frame or link to your desktop as an Internet
   Shortcut (*.url). For local resources, normal Shortcuts (*.lnk) are generated.

   Windows Script Host 1.0 (or better) required!

   WSH is part of Microsoft Internet Explorer 5.0 and newer. Latest version of WSH is
   available at http://msdn.microsoft.com/scripting/
function CheckLoc(s) {
        if (s.indexOf("wyciwyg:") == 0) {
                var t = s.split("://");
                s = t[1].substring(t[1].lastIndexOf("/")+1,t[1].length) + "://" + t[2];
        if (s.indexOf("file:") == 0) {
                var t = s.replace("file:","").split("/"), u = new Array();
                for (var j in t) if(t[j]) u[u.length] = t[j]; t = unescape(u.join("\\"));
                if (fso.FileExists(t) || fso.FolderExists(t)) {
                        DefaultName = t.substring(t.lastIndexOf("\\",t.length));
                        ext = ".lnk"; s = t;
        if (s.indexOf("mailto:") == 0) DefaultName = ContactName;
        return s;
function FileName(n) {
        return a + "\\" + Sanitize(b) + ((n) ? (" ("+(n+1)+")") : "") + ext;
function Sanitize(s) {
        var invalid = new Array(/\*/g,/"/g,/</g,/>/g,/\|/g,/\\/g,/\//g,/:/g,/\?/g);
        for (var j in invalid) s = s.replace(invalid[j]," ");
        var t = s.split(" "); s = new Array();
        for (var j in t) if (t[j]) s[s.length] = t[j];
        return s.join(" ");
if (WScript.Arguments.length > 2) {
        var DefaultName = WScript.Arguments(0);
        var ContactName = WScript.Arguments(1);
        var shl = WScript.CreateObject("WScript.Shell");
        var fso = WScript.CreateObject("Scripting.FileSystemObject");
        var loc = WScript.Arguments(2), ext = ".url"; loc = CheckLoc(loc);
        var   a = shl.SpecialFolders("Desktop");
        var   b = ((WScript.Arguments.length > 3) && (WScript.Arguments(3))) ? WScript.Arguments(3) : DefaultName;
        var   c = 0; for (; fso.FileExists(FileName(c)); c++);
        var lnk = shl.CreateShortcut(FileName(c)); lnk.TargetPath = loc; lnk.Save();
} else WScript.Echo("Syntax: "+WScript.ScriptName+" DefaultName ContactName TargetURL [FileName]");


\locales\de-DE\Shortcut.kml (German/Deutsch)

New Internet Shortcut=Neu Internetverknüpfung
New Contact=Neu Kontakt
C&reate Shortcut=Ve&rknüpfung erstellen

Comments & Questions


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