K-Meleon

KMeleonWiki > Resources > MacroLibrary > MacroLibrary2 > Create Shortcut

Submitted by: kko


New version for KM1.1 + newer: Click HERE


Notes: Old version for KM1.0

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.

Updates:

10-26-05
Minor macro update. Link to Alain's website added.
10-19-05
Shortcut.js updated to version 1.1 to take care of wyciwyg:// URLs. Macros improved to properly
work on pages that have no title.
09-29-05
Macros improved. LinkToDesktop now uses the link's text as shortcut name. FrameToDesktop
now uses the frame's title as shortcut name.


In your profile directory:

Open your profile directory (e.g. C:\Program Files\K-Meleon\Profiles\<ProfileName>\<random>.slt). Create
a new text file there and paste the following:

/* Shortcut.js by kko, version 1.1

   This script is a helper application for K-Meleon's macros.cfg that enables you to send
   the URL of a page, frame or link to your desktop as an Internet Shortcut (*.url file).
   Normal Shortcuts (*.lnk files) are generated for local resources.

   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/
*/
var DefaultName = "New Internet Shortcut"; // edit to your accordance
var ContactName = "New Contact"; // for email addresses
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) {
        var shl = WScript.CreateObject("WScript.Shell");
        var fso = WScript.CreateObject("Scripting.FileSystemObject");
        var loc = WScript.Arguments(0), ext = ".url"; loc = CheckLoc(loc);
        var   a = shl.SpecialFolders("Desktop");
        var   b = ((WScript.Arguments.length > 1) && (WScript.Arguments(1))) ? WScript.Arguments(1) : 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+" TargetURL [FileName]");

Save the file and rename it to "Shortcut.js" (not "Shortcut.js.txt"). Execute (double-click) the script to get a
description of its syntax.


In Macros:

# Send URLs to Windows desktop as Internet Shortcut
PageToDesktop {
        $TITLE==$URL?$u="":$u=gsub("\"","'",$TITLE);
        exec("wscript.exe \"".$path."Shortcut.js\" \"".$URL."\" \"".$u."\"");
}
LinkToDesktop {
        $macro="LnkToDesktop"; &JSEnable;
}
FrameToDesktop {
        $macro="FrmToDesktop"; &JSEnable;
}
LnkToDesktop {
        $TITLE==$URL?$t="":$t=$TITLE;
        open("javascript:function chkLnk(e){var t='".$LinkURL."',l=e.document.links;for(var j=0;j<l.length;j++)if(l[j].href==t){top.document.title=(l[j].text==l[j].innerHTML)?l[j].text:'';break;}}function chkFrm(e){var f=e.frames;for(var j=0;j<f.length;j++)chkFrm(f[j]);chkLnk(e);}void(chkFrm(top));");
        $TITLE==$URL?$u="":$u=gsub("\"","'",$TITLE);
        open("javascript:(function(){top.document.title='".$t."';})();");
        exec("wscript.exe \"".$path."Shortcut.js\" \"".$LinkURL."\" \"".$u."\"");
}
FrmToDesktop {
        $TITLE==$URL?$t="":$t=$TITLE;
        open("javascript:function chkTtl(e){if(unescape(e.document.location.href)==unescape('".$FrameURL."'))top.document.title=e.document.title;}function chkFrm(e){var f=e.frames;for(var j=0;j<f.length;j++)chkTtl(f[j]);chkTtl(e);}void(chkFrm(top));");
        $TITLE==$URL?$u="":$u=gsub("\"","'",$TITLE);
        open("javascript:(function(){top.document.title='".$t."';})();");
        exec("wscript.exe \"".$path."Shortcut.js\" \"".$FrameURL."\" \"".$u."\"");
}
# The file "Shortcut.js" must be located within your profile directory (where this file resides) !


In Menus:

Save{
 bookmarks(Add, Bookmark This Page)
 favorites(Add, Add Page to Favorites)
 hotlist(Add, Add Page to Hotlist)
 %ifplugin macros
 macros(SavePage, Save Page As...)
 macros(EmailURL, Send Page As Link...)
 -
 macros(PageToDesktop, Create Shortcut)
 %else
 Save Page &As... = ID_FILE_SAVE_AS
 %endif
 -
}

Link{
 %ifplugin layers
 layers(OpenLink, Open in New Layer)
 layers(OpenLinkBg, Open in Background Layer)
 -
 %endif
 Open in &New Window = ID_OPEN_LINK_IN_NEW_WINDOW
 Open in Back&ground Window = ID_OPEN_LINK_IN_BACKGROUND
 -
 bookmarks(AddLink, Bookmark This Link)
 favorites(AddLink, Add Link to Favorites)
 hotlist(AddLink, Add Link to Hotlist)
 &Copy Link URL = ID_COPY_LINK_LOCATION
 %ifplugin macros
 macros(SaveLink, Save Link As...)
 macros(LinkInfo, View Link URL...)
 macros(LinkInIE, View Link In IE)
 -
 macros(LinkToDesktop, Create Shortcut)
 %else
 Save &Link As... = ID_SAVE_LINK_AS
 %endif
}

Frame{
 Open Frame = ID_OPEN_FRAME
 %ifplugin layers
 macros(FrameInLayer, Open Frame in New Layer)
 %endif
 Open Frame in New Window = ID_OPEN_FRAME_IN_NEW_WINDOW
 macros(FrameInBack, Open Frame in Background)
 -
 %ifplugin macros
 macros(ReloadFrame, Reload Frame)
 macros(SaveFrame, Save Frame As...)
 macros(EmailFrameURL, Send Frame As Link...)
 -
 macros(FrameToDesktop, Create Shortcut)
 %else
 Save Frame As... = ID_FILE_SAVE_FRAME_AS
 %endif
 -
 View Frame Info =  ID_VIEW_FRAME_INFO
 V&iew Frame Source = ID_VIEW_FRAME_SOURCE
}


Comments & Questions

K-Meleon

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