K-Meleon

KMeleonWiki > Resources > MacroLibrary > KmmShortcut

Submitted by: kko

(macro created because 666 started kicking and screaming on the forum ;)



Notes:

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:

2007-06-19
Localization support added.
2006-11-27
Updated to the K-Meleon 1.1 macro system.
2005-10-26
Minor macro update. Link to Alain's website added.
2005-10-19
Shortcut.js updated to version 1.1 to take care of wyciwyg:// URLs. Macros improved to properly work on pages that have no title.
2005-09-29
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:

Shortcut.kmm

# 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_PageToDesktop{
$_Shortcut_URL=$URL;
$_Shortcut_Title=$TITLE==$URL?"":gsub("\"","'",$TITLE);
&_Shortcut;
}
Shortcut_LinkToDesktop{
$_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;
}
Shortcut_FrameToDesktop{
$_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."'");
&_Shortcut;
}

# ----- PRIVATE

$_Shortcut_Path="";

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

_Shortcut_BuildMenu{
$__c="C&reate Shortcut";
setmenu(DocumentSave,macro,$__c,Shortcut_PageToDesktop,0);
setmenu(LinkSave,macro,$__c,Shortcut_LinkToDesktop,0);
setmenu(FrameSave,macro,$__c,Shortcut_FrameToDesktop,0);
}
$OnInit=$OnInit."_Shortcut_BuildMenu;";

_Shortcut_GetPath{
# 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.
$__data=readfile(getfolder(MacroFolder)."\\Shortcut.kmm");
$_Shortcut_Path=getfolder($__data==""?UserMacroFolder:MacroFolder)."\\Shortcut.js";
}
$OnStartup=$OnStartup."_Shortcut_GetPath;";

# ------------------------------------------------------------------------------------------------------------------
$macroModules=$macroModules."Shortcut;";

Shortcut.js

/* 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]");

Localizations

\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

K-Meleon

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