# ---------- wGetk.kmm # ---------- K-Meleon Macro Language to use wGet when downloading --------------- # # Dependencies : main.kmm # Resources : - # Preferences : - # Version : 0.1 - 12.14.2008 # # need in directory wGet: wget.exe, libeay32.dll, ssleay.dll # download page: http://gnuwin32.sourceforge.net/packages/wget.htm # download link: http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-bin.zip # -------------------------------------------------------------------------------- # find the root folder of K-Meleon $PATH = getfolder(RootFolder); # give a variable the path to the wGet.exe file enclose in quotes $wGetk_Path="\"" . $PATH . "\\wGet\\wGet.exe\""; # this is the scripted save to location for wGet, enclosed in quotes $wGetk_SaveAs="\"c:\\Documents and Settings\\mrwoo\\My Documents\\My Downloads\""; # this is the scripted save to location for the log file, enclosed in quotes $wGetk_Log = "\"c:\\Documents and Settings\\mrwoo\\My Documents\\My Downloads\\wGet_log.txt\""; # ---------- PUBLIC ---------------------------------------------- wGetk_Dload{ # should there be checking for $LinkURL being valid or not ?? # comment out one of the following depending if you want logging or not # this one keeps an appending log of the downloads exec($wGetk_Path . " -a " . $wGetk_Log . " -P " . $wGetk_SaveAs . " " . $LinkURL); # this one does not log at all #exec($wGetk_Path . " -P " . $wGetk_SaveAs . " " . $LinkURL); } wGetk_DloadAs{ # is there a way to see what the extension of the link is ?? # can it be checked, so that the promptforfile can be set correctly ?? # give a variable a path and file name to save this to $_wG_saveme = promptforfile("c:\\","","*.*"); # this one keeps an appending log of the downloads in declared directory exec($wGetk_Path . " -a " . $wGetk_Log . " -P " . $_wG_saveme . " " . $LinkURL); # this one does not log at all #exec($wGetk_Path . " -P " . $_wG_saveme . " " . $LinkURL); # is there any string manipulation to strip out either only directory or filename ?? } # ----- PRIVATE ---------------------------------------------------- _wGetk_BuildMenu{ # context menus for scripted save location.. setmenu(LinkSave,macro,"wGet link",wGetk_Dload,ID_SAVE_LINK_AS); setmenu(ImageSave,macro,"wGet image",wGetk_Dload,ID_SAVE_IMAGE_AS); # context menus for manual choosing save location.. setmenu(LinkSave,macro,"wGet link as..",wGetk_DloadAs,ID_SAVE_LINK_AS); setmenu(ImageSave,macro,"wGet image as..",wGetk_DloadAs,ID_SAVE_IMAGE_AS); # set accel key for save to scripted location setaccel("SHIFT ALT W","macros(wGetk_Dload)"); } $OnInit=$OnInit."_wGetk_BuildMenu;"; # is this needed ? $macroModules=$macroModules."wGetk;"; # End of kmm file --------------------------------------------------
Quote
MrWoo
In addition to the few commented questions in the macro, it would seem that I cannot get the promptforfile() to work correctly. Say I am going to download km_setup.zip. The prompt opens, and I navigate to a directory. Then I write in a filename, such as KM_151_Setup.zip (changed from the LinkURL), then when I press ok, there is an error, that it cannot be done. However, in this instance, the file is downloaded, but it is to KM rootfolder. What is going wrong? Is this a prompt for only opening? How do you prompt for saving? I thought it only returned a path. Should one supply a check for the return? Or is it handled internally?
Quote
K-Meleon Macro
$PATH = promptforfile( INITIAL_FOLDER, FILE_TYPE_DESCRIPTION, FILE_EXTENSION_PATTERN );
Prompts the user for a file, displaying only the files matching the pattern.
$PATH = promptforfolder( CAPTION [, INITIAL_FOLDER] );
Prompts the user for a folder.
$SUB = gensub( r, s, h, t ); Searches the target string t for matches of the string r. If h is a string beginning with g or G, then all matches of r are replace with s. Otherwise, h is a number indicating which match of r to replace. The modified string is returned. $SUB = gsub( r, s, t ); Substitutes the string s for each substring matching the string r in the string t, and returns the modified string. This is equivalent to gensub( r, s, "G", t). $SUB = sub( r, s, t ); Just like gsub(), but only the first matching substring is replaced. This is equivalent to gensub( r, s, 1, t). $SUB = substr( s, i [, n] ); Returns the at most n-character substring of s starting at i. If n is omitted, the rest of s is used. $I = index( s, t ); Returns the index of the string t in the string s, or -1 if t is not present. $LEN = length( s ); Returns the length of the string s. $BASE = basename( URL [, SUFFIX] ); Returns URL with any leading directory components removed. If specified, also remove a trailing SUFFIX. $DIR = dirname( URL ); Returns URL with its trailing /component removed. If URL contains no '/', output '.' (meaning the current directory). $HOST = hostname( URL ); Returns the hostname of the given URL.
I had looked at that, using id(). But I could not see how to use it. Can you give a line example of how it would be implemented. Is it used in a function like promptforfilder?Quote
Are you tried to use ID_FILE_SAVE_AS ?
I will be honest, having used different string manipulation commands in different script languages, this is the most confusing one I have seen. Is it possible you could give a line example of this. Is this like a replacestring? Or more like a search or stringinstring?Quote
$SUB = gensub( r, s, h, t );
Quote
$BASE = basename( URL [, SUFFIX] );
# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage) # # ---------- Training.kmm # ---------- K-Meleon Macro Language Training/Example --------------- # # Dependencies : main.kmm # Resources : - # Preferences : - # Version : - # -------------------------------------------------------------------------------- # _Training_FolderCode{ $_Training_SubFolder=promptforfolder("Select a folder for use", $_Training_Path) ; alert( $_Training_SubFolder, "Folder user selected", "INFO") ; } _Training_GensubCode{ # $SUB = gensub( r, s, h, t ); # Searches the target string t for matches of the string r. # If h is a string beginning with g or G, then all matches # of r are replace with s. Otherwise, h is a number indicating # which match of r to replace. The modified string is returned. $_Training_Target = "copper is a color for corporate" ; alert($_Training_Target, "The target string") ; $_Training_Match = "co" ; $_Training_Replace = "To" ; $_Training_GOut = gensub($_Training_Match, $_Training_Replace, "G" ,$_Training_Target) ; alert($_Training_GOut, "Global replacement", "INFO") ; $_Training_GOut = gensub($_Training_Match, $_Training_Replace, "1" ,$_Training_Target) ; alert($_Training_GOut, "First replacement only", "INFO") ; } _Training_BuildMenu{ # add another option to Help menu $_Training_Popm = "Training" ; setmenu("KMDocs",separator,-1); setmenu("KMDocs",popup,$_Training_Popm); setmenu($_Training_Popm,macro,"PromptForFolder",_Training_FolderCode); setmenu($_Training_Popm,macro,"Gensub",_Training_GensubCode); } _Training_GetPath{ $_Training_Path=getfolder(UserMacroFolder:MacroFolder); } $OnStartup=$OnStartup."_Training_GetPath;"; $OnInit=$OnInit."_Training_BuildMenu;"; $macroModules=$macroModules."Training;";
# ---------- Main Menu --------------------------------------------------------------------------------------------- # ----- File Network{ Work O&ffline=ID_OFFLINE } NavWindow{ Ne&xt Window=ID_WINDOW_NEXT Pre&vious Window=ID_WINDOW_PREV } OpenSave{ &Open...=ID_FILE_OPEN &Save Page As...=ID_FILE_SAVE_AS <<=== } &File{ !New !NavWindow !OpenSave !Print !Network !Close }
gensub(<search string>,<replacment string>,<Flag>,<source string>) <source string> = the string you wish to search in <search string> = the string you wish to find in the <source string> <replacement string> = the string you will replace the <search string> with <Flag> = g or G = indicates that ALL instances of <search string> will be replaced with <replacement string> <Flag> = Integer = indicates WHICH ONE instance of <search string> will be replaced with <replacement string>
OpenSave{ &Open...=ID_FILE_OPEN &Save Page As...=ID_FILE_SAVE_AS <<=== }
$ARG K-Meleon's keyboard accelerators, its menu system and its plugins (but not the macros plugin itself) can call a macro with an argument: setmenu($__m,macro,"&Toolbars","cfg_Skin(toolbars)"); A macro called this way, can get the argument reading the $ARG variable: cfg_Skin{ macroinfo=_("Edit a skin configuration file"); $ext="cfg"; &getExtensionHandler; $cfg_File=$ARG.".".$ext; . . }
Quote
MrWoo
# is this needed ?
$macroModules=$macroModules."wGetk;";
# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage) # # ---------- Training.kmm # ---------- K-Meleon Macro Language Training/Example --------------- # # Dependencies : main.kmm # Resources : - # Preferences : - # Version : - # -------------------------------------------------------------------------------- # _Training_FolderCode{ alert("Allow user to select folder. \n\n No initial folder \n No programed requirement", "Using promptforfolder") ; $_Training_SubFolder=promptforfolder("Select a folder for use") ; alert( $_Training_SubFolder, "Folder user selected", "INFO") ; alert("Allow user to select folder. \n\n Set initial folder to user macro folder \n No programed requirement", "Using promptforfolder") ; $_Training_SubFolder=promptforfolder("Select a folder for use", $_Training_Path) ; alert( $_Training_SubFolder, "Folder user selected", "INFO") ; macros(_Training_FolderCode2) ; } _Training_FolderCode2{ alert("Allow user to select folder. \n\n Set initial folder to Favorites \n Require Favorites or subfolder", "Using promptforfolder") ; #### look three places for the favorites directory $_Training_FavFolder=getpref(STRING,"kmeleon.plugins.favorites.directory"); $_Training_FavFolder==""?$_Training_FavFolder=readreg("HKCU","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0; $_Training_FavFolder==""?$_Training_FavFolder=readreg("HKLM","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0; #### $_Training_FavFolder should have the path for the favorites folder c:\something\favorites #### call _Training_RnameTrue_loop until $_Training_SubFolder is no longer a "?" $_Training_SubFolder="?"; while($_Training_SubFolder=="?") &_Training_NameTrue_loop; $_Training_SubFolder == "" ? alert($_Training_FavFolder, "The selected folder", "INFO") : alert($_Training_FavFolder."\\".$_Training_SubFolder, "The selected folder", "INFO") ; } _Training_NameTrue_loop{ $_Training_SubFolder=promptforfolder (_("Specify where to add the new shortcut. Select your Favorites folder or one of its subfolders:"),$_Training_FavFolder); $_Training_SubFolder=$_Training_SubFolder=="" ? "" : index($_Training_SubFolder,$_Training_FavFolder) == 0 ? substr($_Training_SubFolder,length($_Training_FavFolder)+1) : "?"; } _Training_GensubCode{ # $SUB = gensub( r, s, h, t ); # Searches the target string t for matches of the string r. # If h is a string beginning with g or G, then all matches # of r are replace with s. Otherwise, h is a number indicating # which match of r to replace. The modified string is returned. $_Training_Target = "copper is a color for corporate" ; alert($_Training_Target, "The target string") ; $_Training_Match = "co" ; $_Training_Replace = "To" ; $_Training_GOut = gensub($_Training_Match, $_Training_Replace, "G" ,$_Training_Target) ; alert($_Training_GOut, "Global replacement", "INFO") ; $_Training_GOut = gensub($_Training_Match, $_Training_Replace, "1" ,$_Training_Target) ; alert($_Training_GOut, "First replacement only", "INFO") ; } _Training_BuildMenu{ # add another option to Help menu $_Training_Popm = "Training" ; setmenu("KMDocs",separator,-1); setmenu("KMDocs",popup,$_Training_Popm); setmenu($_Training_Popm,macro,"PromptForFolder",_Training_FolderCode); setmenu($_Training_Popm,macro,"Gensub",_Training_GensubCode); } _Training_GetPath{ $_Training_Path=getfolder(UserMacroFolder:MacroFolder); } $OnStartup=$OnStartup."_Training_GetPath;"; $OnInit=$OnInit."_Training_BuildMenu;"; $macroModules=$macroModules."Training;";
wGetk_DloadAs{ &_downloadFolder = getpref(STRING, "kmeleon.download.dir"); # Or you can use: &_downloadFolder = getpref(STRING, "kmeleon.download.saveDir"); # give a variable a path and file name to save this to $_wG_saveme = promptforfolder("Select a folder for download", &_downloadFolder); $_fileName = prompt("Enter file name:", "wGet downloader"); $_wG_saveme = $_wG_saveme . "\\" . $_fileName; # this one keeps an appending log of the downloads in declared directory exec($wGetk_Path . " -a " . $wGetk_Log . " -P " . $_wG_saveme . " " . $LinkURL); # this one does not log at all #exec($wGetk_Path . " -P " . $_wG_saveme . " " . $LinkURL); }
"%20" space "%3D" = "%2C" . "%2B" + "%26" &
$SUB = gsub( r, s, t );look it in Macro Documentation.
$_new_link = gsub("%20", " ", $LinkURL);