General :  K-Meleon Forum
General discussion about K-Meleon. 
Pages: 123Next
Current Page: 1 of 3
Favorites Rename Add Project
Posted by: James
Date: August 06, 2007 01:08AM

I have decided that it is best to pull together several threads that I have already started into one project thread. This should help everyone who is helping me track the progress as well as reduce new thread proliferation.

This project started as a response to a question by Nav posted on July 26, 2007. See http://kmeleon.sourceforge.net/forum/read.php?1,73404

I have asked and received great help in two additional threads regarding K-Meleon's macro language. See http://kmeleon.sourceforge.net/forum/read.php?1,73580 and http://kmeleon.sourceforge.net/forum/read.php?1,73471

I have working a macro, which sets an item “Rename_Add” into the Favorites menu and allows the user to rename the title for the favorite. It then collects the information needed for writing a favorite in the form of title.url. Currently it only outputs the info to the Windows Clipboard for checking..

After looking and JustBasic and Bloodshed C++, I have decided that KKO’s idea of using JScript and Windows Scripting Host will be best for users. JustBasic would have been easy to code but users would have had to download a runtime engine file, which was over a megabyte in size. I don’t have any experience with C++ libraries so the training time for me would be long. I have ordered textbooks on JScript and WSH and those will take a little time to arrive.

A roadmap of the project ::

Add an item to the Favorites Menu [COMPLETED]

Discover what an Internet Shortcut looks like internally [COMPLETED]

Provide a prompt box where the user can rename the title [COMPLETED]

Add an access key to item the macro places in the menu

Remove unacceptable characters from the renamed title
Windows will not allow some characters to be used in a file name
The title will become the filename of the form title.url

Find how to direct the output to the FAVORITES location
I expect some special folder statement to be in JScript

Check if the renamed title matches an existing shortcut name
If existing add {1} to the title and check again
Is it possible to check all the folders within FAVORITES?

Offer user select and write to a sub-folder
Is it possible or practicable to offer the user a way to add the shortcut to a folder within FAVORITES instead of just the root of FAVORITES?

Provide localizations
Find out how to do localizations and get help translating things

Provide beta code in the forum for testing and feedback

Add the macro in the wiki macro library.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 06, 2007 01:50AM

Have added an access key to the menu item.

&Rename-Add now produces menu item with the R underlined and SHIFT-r runs the macro. Are these key selections global or private to menu in which they appear? Is SHIFT-r likely to colide with anything else?

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: JujuLand
Date: August 06, 2007 02:49AM

I'm not sure to understand what you want to say with 'SHIFT-r runs the macro'.
Do you whant to say this is an accelerator ?

If yes, it's really a bad idea, because each time you use SHIFT-r ( ou R, I suppose) in a field for example, you will then launch Rename.

For an accelerator, look for example if ALT-R or CTRL-R or SHIFT-ALT-R or SHIFT-CTRL-R or CTRL-ALT-R or SHIFT-CTRL-ALT-R (one of these wouldn'd be busy).

A+


Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:31.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/75.0

Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr




Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 06, 2007 03:54AM

@JujuLand

I think the SHIFT+r seems to be private to the Favorites menu. All I added was an amperstand in front of the R in the item I add to the menu. That makes the R in Rename-Add appear with an underscore. Pressing SHIFT + r will run my macro when the Favorites dropdown menu is seen. It does not run the menu unless the Favorites dropdown is showing. If I press SHIFT + r while the cursor is in this text field I just get a capital R. If my cursor is not in a text field when I press SHIFT + r then the cursor just randomly goes to a lowercase r somewhere on the page.

I think the setaccel statement is for command ID and plugin. I did not use that.

The code for the macro so far is as follows:


# K-Meleon Macros
#
# ---------- FavRenAdd.kmm
# ---------- K-Meleon Macro Language Rename/Add page to Favorites ---------------
#
# Dependencies : main.kmm, Favorites plugin active, JScript, Windows Scripting Host
# Resources : -
# Preferences : -
#
# --------------------------------------------------------------------------------
#
_FavRenAdd_RnameTrue{
statusbar("Renaming");
$FavRenAdd_title = substr($FavRenAdd_value,1);
$FavRenAdd_title = $FavRenAdd_title.".url" ;
$FavRenAdd_OutText = $FavRenAdd_title.\n."[InternetShortcut]".\n.$FavRenAdd_CurURL ;
setclipboard( $FavRenAdd_OutText );
}

_FavRenAdd_RenameAdd{
$FavRenAdd_CurrTitle = $TITLE;
$FavRenAdd_CurURL = $URL;
statusbar("Rename Add in progress");
$FavRenAdd_value=prompt($FavRenAdd_CurrTitle,"Rename the Favorite Title here");
# cancel from prompt will return a length of zero to which we add one
$FavRenAdd_value = 1.$FavRenAdd_value;
$FavRenAdd_Len=length($FavRenAdd_value);
# if the length is 1 cancelled was pressed on the prompt box
$FavRenAdd_Len == 1 ? STATUSBAR(Rename _ Add CANCELLED):&_FavRenAdd_RnameTrue ;
}

_FavRenAdd_ModMenu{
# add another option to Favorites menu if favorites plugin is active
$kFavorites==true?setmenu(F&avorites,macro,"&Rename-Add",_FavRenAdd_RenameAdd,1):0;
}

$OnInit=$OnInit."_FavRenAdd_ModMenu;";

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: kko
Date: August 08, 2007 10:43PM

@James: Following two demos for you to gain a better understanding of what you actually have to code and what not. Place the files in your user macro folder (Edit > Configuration > User-Defined Macros). You cannot use both macros at the same time. When you want to use the one, you have to disable the other (under Edit > Advanced Preferences > K-Meleon Plugins > Macro Extension).

I don't want to break your enthusiasm, James - just note the mentioned problems.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: kko
Date: August 08, 2007 10:44PM

1) Use macros and an external application

This code (an update of a previous version) is most probably the easiest example for the use of an external application. It makes use of the Shell.UIHelper ActiveX control (an Internet Explorer component) which is capable to do all we need (removing invalid characters from the link title, showing a dialog where the user can change this title and choose a location, and finally saving the shortcut to disk).

All what's left to do is determining the URL of the current page (or link) and the page's title (or link's text) through macros (and JavaScript). Then we send this information to a Windows script through command line parameters. The script is only needed to create an instance of the Shell.UIHelper ActiveX control and call its AddFavorite() method with these command line parameters as arguments. All the rest is done by the control, we don't need to reinvent the wheel.

Problem: The favorites plugin doesn't notice when an external application is adding shortcuts to the Favorites folder and won't display these in the browser's menu and toolbar until it's reinitialized (i.e. the browser is restarted).


AddFavorite.js:
/* AddFavorite.js by kko, version 1.0

   This script uses Internet Explorer's own "Add to Favorites" function
   to create a new Internet Shortcut. You will be asked for the name and
   the location.

   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/
*/
if (WScript.Arguments.length) {
	var uih = WScript.CreateObject("Shell.UIHelper");
	var cmd = "uih.AddFavorite(WScript.Arguments(0)";
	if ((WScript.Arguments.length > 1) && (WScript.Arguments(1)))
	cmd += ",WScript.Arguments(1)"; eval(cmd+");");
} else WScript.Echo("Syntax: "+WScript.ScriptName+" URL [Title]");

AddFavorite.kmm:
# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ---------- Alternative "Add to Favorites" functionality ----------------------------------------------------------
#
# Dependencies	: main.kmm (JS)
# Resources	: AddFavorite.js
# Preferences	: -
#
# ------------------------------------------------------------------------------------------------------------------

AddFavorite_Page{
# Replacement for plugin command favorites(Add)/plugin(favorites,Add)
$__s=$TITLE==$URL?"":$TITLE;
exec("wscript.exe \"".$_AddFavorite_Path."\" \"".$URL."\" \"".$__s."\"");
}
AddFavorite_Link{
# Replacement for plugin command favorites(AddLink)/plugin(favorites,AddLink)
$__t=$TITLE==$URL?"":$TITLE;
$JS_doitLink="top.document.title=a[j].textContent;j=a.length"; &JS_hndlLink;
$__s=$TITLE==$URL?"":$TITLE;
injectJS("(function(){top.document.title='".$__t."';})();");
exec("wscript.exe \"".$_AddFavorite_Path."\" \"".$LinkURL."\" \"".$__s."\"");
}

# ----- PRIVATE

$_AddFavorite_Path="";

_AddFavorite_BuildMenu{
setmenu("F&avorites",macro,"&Add Page",AddFavorite_Page,"favorites(Add)");
setmenu("F&avorites",command,"","favorites(Add)");
setmenu("DocumentSave",macro,"Add Page To F&avorites",AddFavorite_Page,"favorites(Add)");
setmenu("DocumentSave",command,"","favorites(Add)");
setmenu("LinkSave",macro,"Add Link To F&avorites",AddFavorite_Link,"favorites(AddLink)");
setmenu("LinkSave",command,"","favorites(AddLink)");
}
$kFavorites==true?($OnInit=$OnInit."_AddFavorite_BuildMenu;"):0;

_AddFavorite_GetPath{
# AddFavorite.js is supposed to be located in the same folder as AddFavorite.kmm (this file).
# If it isn't, Windows Script Host will notify the user.
$__data=readfile(getfolder(MacroFolder)."\\AddFavorite.kmm");
$_AddFavorite_Path=getfolder($__data==""?UserMacroFolder:MacroFolder)."\\AddFavorite.js";
}
$kFavorites==true?($OnStartup=$OnStartup."_AddFavorite_GetPath;"):0;

# ------------------------------------------------------------------------------------------------------------------
$kFavorites==true?($macroModules=$macroModules."AddFavorite;"):0;


Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: kko
Date: August 08, 2007 10:45PM

2) Use macros only

This code is a quick demonstration of how you could use macros to choose the location for new favorites before creation. The favorites plugin does already offer a preference to set the folder for new favorites (kmeleon.plugins.favorites.newitemFolder). The value of this pref is the path to a subfolder of the Favorites folder relative to the Favorites folder. With the help of the readreg() and promptforfolder() macro statements we're able to determine the Favorites folder's location and let the user choose a subfolder.

Problems:
1) The favorites plugin doesn't always notice when the pref kmeleon.plugins.favorites.newitemFolder is changed at runtime and thus does not reliably (mostly not) create the new shortcut in the desired location. (See my comment in the code.)
2) The favorites plugin is creating the filename from the document's title or the link's text. To influence the filename we had to manipulate the document. Through the macro language (and JavaScript) we could read as well as alter the document's title, but not the focused link's text (at least not under all circumstances).


AddFavorite2.kmm:
# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ---------- Favorites ---------------------------------------------------------------------------------------------
#
# Dependencies	: -
# Resources	: -
# Preferences	: -
#
# ------------------------------------------------------------------------------------------------------------------

AddFavorite2_Page{
$_FavAction=Add;     &_AddFavorite2;
}
AddFavorite2_Link{
$_FavAction=AddLink; &_AddFavorite2;
}

# ----- PRIVATE

_AddFavorite2{
$_FavFolder=getpref(STRING,"kmeleon.plugins.favorites.directory");
$_FavFolder==""?$_FavFolder=readreg("HKCU","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_FavFolder==""?$_FavFolder=readreg("HKLM","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_SubFolder="?"; while($_SubFolder=="?") &_AddFavorite2_Loop;
$_SubFolder==":"?0:length($_SubFolder)==0?delpref("kmeleon.plugins.favorites.newitemFolder"): setpref(STRING,"kmeleon.plugins.favorites.newitemFolder",$_SubFolder);
# HERE IS THE TRAP
# When the plugin is called below, it's not sure that the pref is already updated from above
$_SubFolder==":"?0: plugin(favorites,$_FavAction);
}
_AddFavorite2_Loop{
$_SubFolder=promptforfolder(_("Specify where to add the new shortcut. Select your Favorites folder or one of its subfolders:"),$_FavFolder."\\".getpref(STRING,"kmeleon.plugins.favorites.newitemFolder"));
$_SubFolder=$_SubFolder==""?":":index($_SubFolder,$_FavFolder)==0?substr($_SubFolder,length($_FavFolder)+1):"?";
}

_AddFavorite2_BuildMenu{
setmenu("F&avorites",macro,"&Add Page",AddFavorite2_Page,"favorites(Add)");
setmenu("F&avorites",command,"","favorites(Add)");
setmenu("DocumentSave",macro,"Add Page To F&avorites",AddFavorite2_Page,"favorites(Add)");
setmenu("DocumentSave",command,"","favorites(Add)");
setmenu("LinkSave",macro,"Add Link To F&avorites",AddFavorite2_Link,"favorites(AddLink)");
setmenu("LinkSave",command,"","favorites(AddLink)");
}
$kFavorites==true?($OnInit=$OnInit."_AddFavorite2_BuildMenu;"):0;

# ------------------------------------------------------------------------------------------------------------------
$kFavorites==true?($macroModules=$macroModules."AddFavorite2;"):0;



Edited 1 time(s). Last edit at 08/08/2007 10:45PM by kko.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 09, 2007 08:08AM

@kko

Thanks. I had not thought of readreg because I know little about the registry.

If newitem folder is not always updated I am not sure about using. I was going to write the shortcut outside of KM. I know that means you don't see the new favorite until you restart KM. Well, we still see deletes until we restart now.

I have to do some thinking about this. Too bad we don't have a Favorites (refresh) statement. Hope my JScript book comes soon.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 10, 2007 07:44PM

@kko

I have used the readreg to find the favorites folder. You are correct about the favorites plugin not seeing the update to newitem perf. I even added the code to handle character not allowed in filenames between folder selection and calling the plugin. I had hoped it was just a timing thing, but must be more. I think I would rather have the shortcut created in the right place so I am moving forward with writing the shortcut outside of KM. That means I have to handle duplicate names for shortcuts in the same folder. I am starting to code that now.

Note: I found some macro statements new to KM 1.1 did not make it into the wiki macro language page. Urlencode and readreg are just two.

Thanks so much for your help.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: james
Date: August 11, 2007 07:01PM

I have run into a small problem while coding the duplicates feature. I am not getting the results that I expected from gsub statement. It is supposed to find the string '[1].url' and replace it with the string '[2].url'. It is only finding and replacing the '[1' so my result looks like 'Something Wicked[2].url].url'. I will include the snippet.kmm I am using for testing.

I hope someone can fix this as it is the last part of macro code, except for the call to JScript, that is needed for the project.

Note the results from snippet are in the clipboard so you have to open an editor like notepad and paste to it.

This is to run in a loop so I cannot just hard code the '[1].url'. You may have to adjust the 3 in the setmenu statement depending on how many items you already have in your favorites menu.

# snippet.kmm

_Snippet_RunCode{

$_integer = 2 ;
$_pathx = "Something Wicked[1].url" ;
$_path_chg = gsub("[".$_integer-1 ."].url" ,"[".$_integer."].url",$_pathx);
setclipboard($_pathx.\n.$_path_chg) ;
}

_Snippet_ModMenu{
# add another option to help menu
setmenu(F&avorites,macro,"Snippet Test",_Snippet_RunCode,3):0;
}

$OnInit=$OnInit."_Snippet_ModMenu;";

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: JujuLand
Date: August 11, 2007 08:18PM

Something is missing in snippet.kmm:

$macroModules=$macroModules."Snippets;");

A+


Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:31.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/75.0

Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr




Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: james
Date: August 11, 2007 09:41PM

@ JujuLand

Yes I missed that. I have fixed it. Any ideas on my gsub problem?

# snippet.kmm

_Snippet_RunCode{

$_integer = 2 ;
$_pathx = "Something Wicked[1].url" ;
$_path_chg = gsub("[".$_integer-1 ."].url" ,"[".$_integer."].url",$_pathx);
setclipboard($_pathx.\n.$_path_chg) ;
}

_Snippet_ModMenu{
# add another option to help menu
setmenu(F&avorites,macro,"Snippet Test",_Snippet_RunCode,3):0;
}

$OnInit=$OnInit."_Snippet_ModMenu;";
$macroModules=$macroModules."Snippet;");

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: JujuLand
Date: August 11, 2007 10:43PM

Sorry, I haven't look at and try your macro.

What and where is your gsub problem ?
What are you waiting for, and what is the result?

To help debugging, put alert() to display the return of your function, like this:

$_integer = 2 ;
$_pathx = "Something Wicked[1].url" ;
alert($_pathx);
alert("[".$_integer-1 ."].url");
alert("[".$_integer."].url");
alert($_pathx);
$_path_chg = gsub("[".$_integer-1 ."].url" ,"[".$_integer."].url",$_pathx);
alert($_pathx.\n.$_path_chg);
setclipboard($_pathx.\n.$_path_chg) ;

You will now be able to debug it, and perhaps correct the parameters of gsub, which are perhaps wrong, or in a bad order.

A+


Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:31.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/75.0

Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr




Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: james
Date: August 12, 2007 02:19AM

@ JujuLand

Thanks for the info on alerts. The item in the gsub statement that is not resolving correctly is "[".$_integer-1 ."].url". It is resolving to [1 but should be resolving to [1].url. It is a string "[" concanted to a variable -1 expression concanted to another string "].url".

Found the problem. I cannot have the variable -1 expression within the gsub statement. I had to resolve that outside the gsub statement so I could have only a variable but no expression. Note the third line where $_integer -1 is assigned to $_work_int. I can use $_work_int in the gsub statement with a problem.

$_integer = 2 ;
$_pathx = "Something Wicked[1].url" ;
$_work_int = $_integer -1 ;
alert($_pathx);
alert("[".$_work_int."].url");
alert("[".$_integer."].url");
alert($_pathx);
$_path_chg = gsub("[".$_work_int."].url" ,"[".$_integer."].url",$_pathx);
alert($_pathx.\n.$_path_chg);
setclipboard($_pathx.\n.$_path_chg) ;

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: JujuLand
Date: August 12, 2007 02:45AM

You can perhaps also try to put the expression between (), like this:

$_path_chg = gsub("[".($_integer-1) ."].url" ,"[".$_integer."].url",$_pathx);

it's possible that the expression is evaluated before being passed to gsub.

A+


Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:31.0) Gecko/20100101 Ubuntu/12.04 K-Meleon/75.0

Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr




Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 13, 2007 01:11AM

Can anyone advise me on the form of the exec statement in the macro language for calling wscript.exe and passing two arguments? Based on one example I am using the following statement:

exec("wscript.exe\"".$_FavRenAdd_PathName."\" \"".$_FavRenAdd_CurURL."\"") ;

I think it resolves to this:

""C:\\Documents and Settings\\Compaq_Owner.JIM-BARBARA\\Favorites\\Unfiled-New\\Group_3\\Something wicked.url" "http://www.perigee.net/"";

That is two quoted strings inside a quoted string. Is this right? I am not having any luck so far with the jscript program.

I think the macro language part of the project is done except for some cleanup of leftover comments and stuff. I will post here for anyone who cares to see how it looks to the user when run. NOTE: it does not yet actualy create a shortcut. I have to get the exec statement right and complete the jscript program for that.

# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- FavRenAdd.kmm
# ---------- K-Meleon Macro Language Rename/Add page to Favorites ---------------
#
# Dependencies : main.kmm, Favorites plugin active, JScript, Windows Scripting Host
# Resources : -
# Preferences : -
#
# --------------------------------------------------------------------------------
#
_FavRenAdd_RnameTrue{
statusbar("Renaming");
$_FavRenAdd_NewItemFolder = getpref( string, "kmeleon.plugins.favorites.newitemFolder" );

#### look three places for the favorites directory

$_FavRenAdd_FavFolder=getpref(STRING,"kmeleon.plugins.favorites.directory");
$_FavRenAdd_FavFolder==""?$_FavRenAdd_FavFolder=readreg("HKCU","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_FavRenAdd_FavFolder==""?$_FavRenAdd_FavFolder=readreg("HKLM","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;

#### $_FavRenAdd_FavFolder should have the path for the favorites folder c:\something\favorites
#### call _FavRenAdd_RnameTrue_loop until $_FavRenAdd_SubFolder is no longer a "?"

$_FavRenAdd_SubFolder="?"; while($_FavRenAdd_SubFolder=="?") &_FavRenAdd_RnameTrue_loop;


$_FavRenAdd_title = substr($_FavRenAdd_value,1);
macros(_FavRenAdd_Sanitize_Title) ;

$_FavRenAdd_PathName = $_FavRenAdd_FavFolder."\\".$_FavRenAdd_SubFolder.\\.$_FavRenAdd_title.".url" ;
$_FavRenAdd_Ext_Interger = 1;
while ($_FavRenAdd_Ext_Interger > 0 ) &_FavRenAdd_Duplicates_loop) ;
$_FavRenAdd_OutText =$_FavRenAdd_PathName.\n.$_FavRenAdd_CurURL ;
$_FavRenAdd_PathName = gsub(\\ , \\\\, $_FavRenAdd_PathName);
exec("wscript.exe\"".$_FavRenAdd_PathName."\" \"".$_FavRenAdd_CurURL."\"") ;
setclipboard(\"".$_FavRenAdd_PathName."\" \"".$_FavRenAdd_CurURL."\" );

#setclipboard( $_FavRenAdd_OutText );
statusbar("Rename-Add COMPLETE");
}

_FavRenAdd_Sanitize_Title{
$_FavRenAdd_RevTitle = gsub( ".","",$_FavRenAdd_title);
$_FavRenAdd_RevTitle = gsub( "?","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( ":","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "*","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "<","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( ">","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "/","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "|","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "\\","",$_FavRenAdd_RevTitle);
$_FavRenAdd_title = gsub( "\"","^",$_FavRenAdd_RevTitle);
}

_FavRenAdd_Duplicates_loop{
$_FavRenAdd_Exists=readfile($_FavRenAdd_PathName);
$_FavRenAdd_Exists=1.$_FavRenAdd_Exists ;
$_FavRenAdd_Len2=length($_FavRenAdd_Exists);
$_FavRenAdd_Len2 == 1 ? $_FavRenAdd_Ext_Interger=0 : &_FavRenAdd_Extend;
}

_FavRenAdd_Extend{
$_FavRenAdd_Wrk_Int = $_FavRenAdd_Ext_Interger - 1 ;
$_FavRenAdd_Ext_Interger == 1 ? $_FavRenAdd_PathName = gsub(".url" , "[".$_FavRenAdd_Ext_Interger."].url",$_FavRenAdd_PathName):0;
$_FavRenAdd_Ext_Interger > 1 ? $_FavRenAdd_PathName = gsub("[".$_FavRenAdd_Wrk_Int."].url" , "[".$_FavRenAdd_Ext_Interger."].url" , $_FavRenAdd_PathName):0;
$_FavRenAdd_Ext_Interger = $_FavRenAdd_Ext_Interger + 1 ;
}

_FavRenAdd_RnameTrue_loop{
$_FavRenAdd_SubFolder=promptforfolder("Specify where to add the new shortcut. Select your Favorites folder or one of its subfolders:",$_FavRenAdd_FavFolder."\\".$_FavRenAdd_NewItemFolder);
$_FavRenAdd_SubFolder=$_FavRenAdd_SubFolder==""?":":index($_FavRenAdd_SubFolder,$_FavRenAdd_FavFolder)==0?substr($_FavRenAdd_SubFolder,length($_FavRenAdd_FavFolder)+1):"?";
}

_FavRenAdd_RenameAdd{
$_FavRenAdd_CurrTitle = $TITLE;
$_FavRenAdd_CurURL = $URL;
statusbar("Rename Add in progress");
$_FavRenAdd_value=prompt($_FavRenAdd_CurrTitle,"Rename the Favorite Title here");
# cancel from prompt will return a length of zero to which we add one
$_FavRenAdd_value = 1.$_FavRenAdd_value;
$_FavRenAdd_Len=length($_FavRenAdd_value);
# if the length is 1 cancelled was pressed on the prompt box
$_FavRenAdd_Len == 1 ? &_FavRenAdd_Cancelled :&_FavRenAdd_RnameTrue ;
}

_FavRenAdd_Cancelled{
statusbar(Rename-Add CANCELLED)
$FavRenAdd_Button=confirm("Did you mean to cancel?","Confirm" ,YESNO,QUESTION);
$FavRenAdd_Button == "YES" ? statusbar(Rename-Add CANCELLED): &_FavRenAdd_RenameAdd ;
}

_FavRenAdd_ModMenu{
# add another option to Favorites menu if favorites plugin is active
$kFavorites==true?setmenu(F&avorites,macro,"&Rename-Add",_FavRenAdd_RenameAdd,1):0;
}

_FavRenAdd_GetPath{
# FavRenAdd.js is supposed to be located in the same folder as FavRenAdd.kmm (this file).
# If it isn't, Windows Script Host will notify the user.
$_FavRenAdd_Data=readfile(getfolder(MacroFolder)."\\FavRenAdd.kmm");
$_FavRenAdd_Path=getfolder($_FavRenAdd_Data==""?UserMacroFolder:MacroFolder)."\\FavRenAdd.js";
}



$OnStartup=$OnStartup."_FavRenAdd_GetPath;";
$OnInit=$OnInit."_FavRenAdd_ModMenu;";
$macroModules=$macroModules."FavRenAdd;";

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 13, 2007 03:06AM

Still looking for help on the jscript. ( see previous post}

Am re-posting the roadmap showing sections completed to date.

A roadmap of the project ::

Add an item to the Favorites Menu [COMPLETED]

Discover what an Internet Shortcut looks like internally [COMPLETED]

Provide a prompt box where the user can rename the title [COMPLETED]

Add an access key to item the macro places in the menu [COMPLETED]

Remove unacceptable characters from the renamed title [COMPLETED]
Windows will not allow some characters to be used in a file name
The title will become the filename of the form title.url

Find how to direct the output to the FAVORITES location [COMPLETED]
I expect some special folder statement to be in JScript
Was done in the macro language

Check if the renamed title matches an existing shortcut name [COMPLETED]
If existing add [1] to the title and check again
Is it possible to check all the folders within FAVORITES?
Checks only user chosen folder

Offer user select and write to a sub-folder [COMPLETED]
Is it possible or practicable to offer the user a way to add the shortcut to a folder within FAVORITES instead of just the root of FAVORITES?

Write a FavRenAdd.js file to write the new, renamed favorite to disk

Provide localizations
Find out how to do localizations and get help translating things

Provide beta code in the forum for testing and feedback [PARTIAL]
FavRenAdd.kmm posted in forum Aug-12-07

Add the macro in the wiki macro library.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: kko
Date: August 13, 2007 07:10PM

Quote
James
I found some macro statements new to KM 1.1 did not make it into the wiki macro language page. Urlencode and readreg are just two.

readreg and urlencode were introduced with km 1.0. They're listed. However, readreg was listed with a wrong name (readkey). I've corrected that.


Quote
James
Can anyone advise me on the form of the exec statement in the macro language for calling wscript.exe and passing two arguments? Based on one example I am using the following statement:

exec("wscript.exe\"".$_FavRenAdd_PathName."\" \"".$_FavRenAdd_CurURL."\"") ;

See my example. Command line parameters always have to be separated with a white space. The first parameter for wscript.exe must be the path of the script file to execute. Any other parameters are simply passed on to the script.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: Nith
Date: August 14, 2007 12:43AM

I hope everyone appreciates all of your efforts as much as I do. I have been waiting
a very long time for KM to be able to rename Favorites. I am wondering if there may
be even a slight chance that such a change in the browser would also fix problems
myself and others are having. They are mentioned in these two threads.

http://kmeleon.sourceforge.net/forum/read.php?1,73704

http://kmeleon.sourceforge.net/forum/read.php?1,43325

Thanks to all contributors of the Favorites Rename Add Project.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 14, 2007 06:21AM

@ Nith

Let's make sure everyone is on the same page for this project. It is for renaming the favorites that are shared between IE and KM. I do not have bookmarks or hotlist turned on in my setup. Sorry if anyone hopes this will fix bookmarks. It will not.

When complete this macro will let users do a rename-add of a favorite. The user will also have the option of selecting which folder to which the renamed favorite will be added. This should be Favorites or a sub-folder under Favorites. The write to Favorites will occur outside of KM which means KM must be restarted in order to use.

@kko

Sorry about the stuff in the wiki. Guess my eyeballs are getting as old as I am. I better start using "Find in Page" instead. I have made some progress on linking the macro to the script. Hard coded in snippet it works but not yet in FavRenAdd. Will be away from home to visit family for two day, so will be a while before I get back to work.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 17, 2007 04:23AM

Just an update - -

I am pleased to report that I have the macro and Jscript files working together now. There is only some event trapping to do for when the user chooses “cancel” from either the rename prompt or the folder choice prompt. Hopefully that will not take much longer.

@ Nith
I just realized that my answer to your post was very abrupt. I apologize for being less than diplomatic in that answer. Both the threads you included seemed to me to talking of bookmarks rather than favorites. I have never used bookmarks. I guess I will need to try them out just to see what so many users are talking about.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 17, 2007 11:26PM

As has been promised, here is the beta code for FavRenAdd.

This macro will allow a user to change the name of a favorite during the add process and allow the user to select which folder/subfolder in Favorites to which the renamed favorite will be added.

IMPORTANT NOTES:
The favorite is written as an internet shortcut of the style filename.url bye Windows Scripting Host outside of K-melon. That means KM will have to be stopped and re-started before you can see/use the favorite.
The user may cancel from the rename prompt and the process will be aborted. A cancel from the folder prompt will result in the default folder being used. That will be Favorites unless the preference for new items has been set to a subfolder of Favorites.

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.

Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder
(Edit > Configuration > Macros) and create the following text files:

FavRenAdd.kmm

# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- FavRenAdd.kmm
# ---------- K-Meleon Macro Language Rename/Add page to Favorites ---------------
#
# Dependencies : main.kmm, Favorites plugin active, JScript, Windows Scripting Host
# Resources : -
# Preferences : -
# Version : 0.8
# --------------------------------------------------------------------------------
#
_FavRenAdd_RnameTrue{
statusbar("Renaming");
$_FavRenAdd_NewItemFolder = getpref( string, "kmeleon.plugins.favorites.newitemFolder" );
#### look three places for the favorites directory
$_FavRenAdd_FavFolder=getpref(STRING,"kmeleon.plugins.favorites.directory");
$_FavRenAdd_FavFolder==""?$_FavRenAdd_FavFolder=readreg("HKCU","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_FavRenAdd_FavFolder==""?$_FavRenAdd_FavFolder=readreg("HKLM","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
#### $_FavRenAdd_FavFolder should have the path for the favorites folder c:\something\favorites
#### call _FavRenAdd_RnameTrue_loop until $_FavRenAdd_SubFolder is no longer a "?"
$_FavRenAdd_SubFolder="?"; while($_FavRenAdd_SubFolder=="?") &_FavRenAdd_RnameTrue_loop;
$_FavRenAdd_title = substr($_FavRenAdd_value,1);
macros(_FavRenAdd_Sanitize_Title) ;
$_FavRenAdd_PathName = $_FavRenAdd_FavFolder."\\".$_FavRenAdd_SubFolder.\\.$_FavRenAdd_title.".url" ;
$_FavRenAdd_Ext_Interger = 1;
while ($_FavRenAdd_Ext_Interger > 0 ) &_FavRenAdd_Duplicates_loop) ;
$_FavRenAdd_OutText =$_FavRenAdd_PathName.\n.$_FavRenAdd_CurURL ;
$_FavRenAdd_PathName = gsub("\\" , "\\\\", $_FavRenAdd_PathName);
exec("wscript.exe \"".$_FavRenAdd_Path."\" \"".$_FavRenAdd_PathName."\" \"".$_FavRenAdd_CurURL."\"") ;
statusbar("Rename-Add COMPLETE");
}

_FavRenAdd_Sanitize_Title{
$_FavRenAdd_RevTitle = gsub( ".","",$_FavRenAdd_title);
$_FavRenAdd_RevTitle = gsub( "?","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( ":","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "*","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "<","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( ">","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "/","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "|","",$_FavRenAdd_RevTitle);
$_FavRenAdd_RevTitle = gsub( "\\","",$_FavRenAdd_RevTitle);
$_FavRenAdd_title = gsub( "\"","^",$_FavRenAdd_RevTitle);
}

_FavRenAdd_Duplicates_loop{
$_FavRenAdd_Exists=readfile($_FavRenAdd_PathName);
$_FavRenAdd_Exists=1.$_FavRenAdd_Exists ;
$_FavRenAdd_Len2=length($_FavRenAdd_Exists);
$_FavRenAdd_Len2 == 1 ? $_FavRenAdd_Ext_Interger=0 : &_FavRenAdd_Extend;
}

_FavRenAdd_Extend{
$_FavRenAdd_Wrk_Int = $_FavRenAdd_Ext_Interger - 1 ;
$_FavRenAdd_Ext_Interger == 1 ? $_FavRenAdd_PathName = gsub(".url" , "[".$_FavRenAdd_Ext_Interger."].url",$_FavRenAdd_PathName):0;
$_FavRenAdd_Ext_Interger > 1 ? $_FavRenAdd_PathName = gsub("[".$_FavRenAdd_Wrk_Int."].url" , "[".$_FavRenAdd_Ext_Interger."].url" , $_FavRenAdd_PathName):0;
$_FavRenAdd_Ext_Interger = $_FavRenAdd_Ext_Interger + 1 ;
}

_FavRenAdd_RnameTrue_loop{
$_FavRenAdd_SubFolder=promptforfolder("Specify where to add the new shortcut. Select your Favorites folder or one of its subfolders:",$_FavRenAdd_FavFolder."\\".$_FavRenAdd_NewItemFolder);
$_FavRenAdd_SubFolder=$_FavRenAdd_SubFolder=="" ? "" : index($_FavRenAdd_SubFolder,$_FavRenAdd_FavFolder) == 0 ? substr($_FavRenAdd_SubFolder,length($_FavRenAdd_FavFolder)+1) : "?";
$_FavRenAdd_SubFolder == "" ? $_FavRenAdd_SubFolder = $_FavRenAdd_NewItemFolder : 0 ;
}

_FavRenAdd_RenameAdd{
$_FavRenAdd_CurrTitle = $TITLE;
$_FavRenAdd_CurURL = $URL;
statusbar("Rename Add in progress");
$_FavRenAdd_value=prompt($_FavRenAdd_CurrTitle,"Rename the Favorite Title here");
### cancel from prompt will return a length of zero to which we add one
$_FavRenAdd_value = 1.$_FavRenAdd_value;
$_FavRenAdd_Len=length($_FavRenAdd_value);
### if the length is 1 cancelled was pressed on the prompt box
$_FavRenAdd_Len == 1 ? &_FavRenAdd_Cancelled :&_FavRenAdd_RnameTrue ;
}

_FavRenAdd_Cancelled{
statusbar(Rename-Add CANCELLED)
$FavRenAdd_Button=confirm("Did you mean to cancel?","Confirm" ,YESNO,QUESTION);
$FavRenAdd_Button == "YES" ? statusbar(Rename-Add CANCELLED): &_FavRenAdd_RenameAdd ;
}

_FavRenAdd_ModMenu{
### add another option to Favorites menu if favorites plugin is active
$kFavorites==true?setmenu(F&avorites,macro,"&Rename-Add",_FavRenAdd_RenameAdd,1):0;
}

_FavRenAdd_GetPath{
### FavRenAdd.js is supposed to be located in the same folder as FavRenAdd.kmm (this file).
### If it isn't, Windows Script Host will notify the user.
$_FavRenAdd_Data=readfile(getfolder(MacroFolder)."\\FavRenAdd.kmm");
$_FavRenAdd_Path=getfolder($_FavRenAdd_Data==""?UserMacroFolder:MacroFolder)."\\FavRenAdd.js";
}

$OnStartup=$OnStartup."_FavRenAdd_GetPath;";
$OnInit=$OnInit."_FavRenAdd_ModMenu;";
$macroModules=$macroModules."FavRenAdd;";

FavRenAdd.js

/* FavRenAdd.js by James, version 0.8

This script is a helper application for the K-Meleon Macro Module FavRenAdd.kmm that
enables you to rename a favorite, select a folder, and write the favorite to that folder.

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/
*/

if(WScript.Arguments.count()==2)
{
var FavRenAddFileName = WScript.Arguments(0);
var FavRenAddDescription = WScript.Arguments(1);
var WshShell = new ActiveXObject("WScript.Shell")
var oShellLink = WshShell.CreateShortcut(FavRenAddFileName);
oShellLink.TargetPath = FavRenAddDescription;
oShellLink.Save();
}
else
{
objArgs = WScript.Arguments ;
WScript.Echo(WScript.Arguments.Count());
for (i=0; i<objArgs.length; i++)
{
WScript.Echo(objArgs(i))
}
}

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: Nith
Date: August 18, 2007 02:14AM

@James

Often my writing is not clear. Sorry about that James. You may have missed some of
my posts. I must clarify that 99 percent of my concern are the Favorites. Here is
one of my posts from this thread

http://kmeleon.sourceforge.net/forum/read.php?1,43325,page=2


Thanks KKO. I mean the Favorites menu. In Preferences, then under Plugins I have
several items activated including Bookmarks, Hotlist and the Favorites plugin.
But the weird thing is Favorites menu does not show up. Still weirder is the
Favorites toolbar does appear. But it does not function correctly. On the far left
where it has the button to open the Favorites menu it does not work correctly.
Opening it just brings open a very thin line. But if you move the mouse pointer
along it the various folders will open. This is truly bizarre so I am open to trying anything. Thanks to all.


Seems from that particular page that Furl has the same problems and I believe
Flekto has expressed the same.

So I and I believe others are very desperate for a solution to the IE Favorites
problem. You say you never use Bookmarks. It is basically the same for me. The
ONLY time I ever use other than the IE Favorites is when on Opera or Seamonkey.

So Favorites are my Favorites and I am much hoping for a solution to the problem
with them.

What you have done so far is a great beginning as I have always wanted to be able
to rename them in K-Meleon.

Thanks for all your efforts. Have a wonderful weekend.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: James
Date: August 18, 2007 07:51PM

I am considering two changes to FavRenAdd before making an official release.

The first is to remove all of the writes to the statusbar. The results that I am see in testing are somewhat inconsistent. If the cursor is on some item in the page that shows in the statusbar then that overwrites anything that I put there. Also the alert if a user selects cancel from the rename prompt writes a zero to the statusbar.

The second is to seed the rename text entry field with the current title of the screen. That way the user does not have to type text that he/she may wish to use from the current title. Titles that exceed 73 characters wrap in the prompt box and are hard to read. Should I truncate the title to 73 characters?

That brings up another question about the favorite title. When using favorites the user can see only the first forty characters. It is possible to have more than one entry where the first forty characters are identical. I do not know if this situation will be more or less likely using rename. Should the macro check to see if the length of the renamed title is greater than 40 and warn the user?

Any suggestions or comments on these or any other aspect of the FavRenAdd macro will be gratefully appreciated.

@Nith

I hope you get your favorites menu working. That is where this macro shows up.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: JamesD
Date: August 21, 2007 02:56AM

I need some help with getting this macro loaded into the wiki. I know I need to paste a templete from the macro templete into my page. I just don't know where to get my page. Do I put a link in the macro library before I create my page? Looks like someone might click the link and not find a page ready.

I had to register on the wiki. James was in use so now I guess I an JamesD.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: kko
Date: August 21, 2007 03:20AM

@JamesD:

1) Got to the MacroLibrary.
2) Click the British country flag in the green bar on the left. This is to ensure that you will edit the right page.
3) Then click on EditThisPage at the bottom of the MacroLibrary page.
4) Add your link to the list. Use kmmFavRenAdd or something like that as the name for your page (the target of the link). The name of the link can be whatever you want. Save your changes (check the preview first).
5) Open the macro submission template in a new layer and edit it. Copy the markup to the clipboard.
6) Go back to the macro library and click on the link you've created. Paste the markup you've copied from the template and edit it to your accordance. Use the preview before finally saving it.

Don't care about others - just do your thing.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: JamesD
Date: August 21, 2007 06:27AM

I did not do something right. I typed this line into the edit page for the macrolibrary.

*[FavRenAdd | KmmFavRenAdd]--2007-08-20-- - Rename Internet Shortcuts (*.url) to Favorites.

FavRenAdd should have been a link in blue letters. Instead I got it in Bold type followed by a ?

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: kko
Date: August 21, 2007 06:44AM

That's alright, James. Simply click the question mark and paste your code. Once the page is existing, the link will look right, too.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: JamesD
Date: August 21, 2007 08:34PM

Something did not happen as I expected when trying to create the kmmFavRenAdd page. There was just plain code copied in but the results are very different. The page exists http://kmeleon.sourceforge.net/wiki/KmmFavRenAdd but is not what a user would need.

Options: ReplyQuote
Re: Favorites Rename Add Project
Posted by: kko
Date: August 21, 2007 10:29PM

I see. I guess, I have to help you a bit...

Options: ReplyQuote
Pages: 123Next
Current Page: 1 of 3


K-Meleon forum is powered by Phorum.