KMeleonWiki > Resources > MacroLibrary > Create Shortcut

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.


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.0

   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("file:") == 0) {
        var t = s.replace("file:","").split("/"), u = new Array();
        for (var j in t) if(tj?) uu.length? = tj?; 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(invalidj?," ");
        var t = s.split(" "); s = new Array();
        for (var j in t) if (tj?) ss.length? = tj?;
        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) : 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? {
        exec("wscript.exe \"".$path."Shortcut.js\" \"".$URL."\" \"".$TITLE."\"");
LinkToDesktop? {
        $macro="LnkToDesktop?"; &JSEnable;
FrameToDesktop? {
        $macro="FrmToDesktop?"; &JSEnable;
LnkToDesktop? {
        open("javascript:function chkLnk(e){var t='".$LinkURL."',l=e.document.links;for(var j=0;j<l.length;j)if(lj?.href==t){top.document.title=lj?.text;break;}}function chkFrm(e){var f=e.frames;for(var j=0;j<f.length;j)chkFrm(fj?);chkLnk(e);}void(chkFrm(top));");
        exec("wscript.exe \"".$path."Shortcut.js\" \"".$LinkURL."\" \"".$u."\"");
FrmToDesktop? {
        open("javascript:function chkTtl(e){if(e.document.location.href=='".$FrameURL."')top.document.title=e.document.title;}function chkFrm(e){var f=e.frames;for(var j=0;j<f.length;j++)chkTtl(fj?);chkTtl(e);}void(chkFrm(top));");
        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:

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)

Save Page &As... = ID_FILE_SAVE_AS

%ifplugin layers
layers(OpenLink, Open in New Layer)
layers(OpenLinkBg, Open in Background Layer)
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)
%ifplugin macros
macros(SaveLink, Save Link As...)
macros(LinkInfo, View Link URL...)
macros(LinkInIE, View Link In IE)

macros(LinkToDesktop?, Create Shortcut)

Save &Link As... = ID_SAVE_LINK_AS

Open Frame = ID_OPEN_FRAME
%ifplugin layers
macros(FrameInLayer, Open Frame in New Layer)
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)

Save Frame As... = ID_FILE_SAVE_FRAME_AS
View Frame Info = ID_VIEW_FRAME_INFO
V&iew Frame Source = ID_VIEW_FRAME_SOURCE

Comments & Questions


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