K-Meleon
KMeleonWiki > Resources > MacroLibrary > KmmShortcut
Submitted by: kko
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.
This macro works OK on K-Meleon versions before version 1.5. If you have K-Meleon version 1.5, search the .kmm file for # K-Meleon 1.5, remove the # for the line right under it, and add a # to the line below # K-Meleon prior to 1.5:.
Updates:
Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder
(Edit > Configuration > Macros) and create the following text files:
# -------- Send URLs to Windows desktop as Internet Shortcut (*.url) ---------- # # K-Meleon Macro (http://kmeleon.sourceforge.net/wiki/KmmShortcut) # For help, see http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage # # 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_Menu="C&reate Shortcut"; _Shortcut{ index($_Shortcut_URL,"wyciwyg:")==0?$_Shortcut_URL=substr($_Shortcut_URL,index($_Shortcut_URL,hostname($_Shortcut_URL))+length(hostname($_Shortcut_URL))+1):0; # $_max: The length of the command line must not exceed 258 characters! $_max=258; $_cmd="wscript.exe \"".$_Shortcut_Path."\" \"".$_Shortcut_URL."\""; $_len=length($_cmd); # K-Meleon 1.5: #$_len>$_max?&_Shortcut_Error:($_len>$_max-4?exec($_cmd):&_Shortcut_Create); # K-Meleon prior to 1.5: ($_len-$_max)>0?&_Shortcut_Error:(($_len-$_max+4)>0?exec($_cmd):&_Shortcut_Create); } _Shortcut_Create{ $_Shortcut_Title==""?($_Shortcut_Title=index($_Shortcut_Title,"mailto:")==0?_("New Contact"):_("New Internet Shortcut")):0; $_cmd=$_cmd." \"".substr($_Shortcut_Title,0,$_max-3-$_len)."\""; exec($_cmd); } _Shortcut_Error{ setclipboard($_Shortcut_URL); alert(_("Unable to create shortcut - URL too long!\n\nThe URL was copied to the clipboard."),gsub("&","",_($_Shortcut_Menu)),EXCLAIM); } _Shortcut_BuildMenu{ setmenu(DocumentSave,macro,$_Shortcut_Menu,Shortcut_PageToDesktop,0); setmenu(LinkSave,macro,$_Shortcut_Menu,Shortcut_LinkToDesktop,0); setmenu(FrameSave,macro,$_Shortcut_Menu,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 by kko, version 1.3.1 This 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 file (*.url). For local resources, standard Shortcut files (*.lnk) are generated. Windows Script Host (WSH) 1.0, or better, required! WSH is part of MS Internet Explorer version 5.0 and newer; latest version of WSH is available for download from 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.substr(0,loc.length-1):loc; def = def.substring(def.lastIndexOf("/")+1,def.length); 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]");
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.