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.


Shortcut.js updated to version 1.3. Macro takes care of the command line's length (which is limited).
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

$_Shortcut_Menu="C&reate Shortcut";

# $_max: The length of the command line must not exceed 258 characters!
$_max=258; $_cmd="wscript.exe \"".$_Shortcut_Path."\" \"".$_Shortcut_URL."\"";
$_Shortcut_Title==""?($_Shortcut_Title=index($_Shortcut_Title,"mailto:")==0?_("New Contact"):_("New Internet Shortcut")):0;
$_cmd=$_cmd." \"".substr($_Shortcut_Title,0,$_max-3-length($_cmd))."\""; exec($_cmd);
setclipboard($_Shortcut_URL); alert(_("Unable to create shortcut - URL too long!\n\nThe URL was copied to the clipboard."),gsub("&","",_($_Shortcut_Menu)),EXCLAIM);


# 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.3

   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("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)) {
                        def = t.substring(t.lastIndexOf("\\",t.length));
                        ext = ".lnk"; s = t;
        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 > 0) {
        var shl = WScript.CreateObject("WScript.Shell");
        var fso = WScript.CreateObject("Scripting.FileSystemObject");
        var loc = WScript.Arguments(0), ext = ".url";
        var def = loc.lastIndexOf("/")==loc.length-1?loc:loc.substr(0,loc.length-1);
            def = def.substring(def.lastIndexOf("/")+1,def.length-1);
            loc = CheckLoc(loc);
        var   a = shl.SpecialFolders("Desktop");
        var   b = ((WScript.Arguments.length > 1) && (WScript.Arguments(1))) ? WScript.Arguments(1) : def;
        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+" 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
Unable to create shortcut - URL too long!\n\nThe URL was copied to the clipboard.=Verknüpfung kann nicht erstellt werden - URL zu lang!\n\nDie Adresse wurde in die Zwischenablage kopiert.

Comments & Questions


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