General :  K-Meleon Web Browser Forum
General discussion about K-Meleon 
Problem with download macro
Posted by: ra
Date: March 13, 2011 04:41PM

Hi,

I'd like to build a macro that downloads files from file1 to file9 and saves them to the harddisc. Unfortunately calling ID_SAVE_LINK_AS(<url to file>) is not supported by K-M, so I tried some workarounds. Here is a toy example to illustrate the problem:

download stuff {
	$linkIdx = "http://kmeleon.sourceforge.net/gfx/shot";;
	$ext = ".png";
	$i=3;
	while($i<5) {
		open( $linkIdx . $i . $ext );
		id(ID_FILE_SAVE_AS);
		$i = $i+1;
	}
}

But the call to FileSaveAs happens too early, it does not save the URL that's (still) loading, but the one before. If I open the URL in a new tab I get a similar problem.

I'd like to get this done without third party applications.

Any suggestions?

BTW: It would be perfect if there was only one save prompt for the folder where to save the files, not a save dialog for each file.

Thanks

Options: ReplyQuote
Re: Problem with download macro
Posted by: siria
Date: March 13, 2011 07:49PM

Welcome in the club :cool: I can't count the number of gray hairs and the countless hours I've wasted with that stupid prob of lacking sequentiality (or how to call it) in macros sad smiley Have a few unfinished monster macros silently buried because of that (to me) unsolvable prob. It was already a nightmare in KM1.5, but KM1.6 (=gecko 1.9) is ten times worse yet!
A lousy workaround which helped at least sometimes was to insert a little manual pause by an alert command, which the user has to confirm first, e.g. by tapping the space bar. Even if it was only a split second which the macro would have to wait to get the correct 'next' action, it just would not work without that stupid pause alert.

In your specific case, perhaps your best bet would be to open all those files in new tabs first, all together in one new window, and when the last one has finished (OnLoad), use the FileAllTabs-macro? (Haven't used it personally, but sounds like it might help here)

PS: You really use blanks in macro names, does that work?? Or was that just an example name...?



Edited 1 time(s). Last edit at 03/13/2011 08:17PM by siria.

Options: ReplyQuote
Re: Problem with download macro
Posted by: JamesD
Date: March 13, 2011 09:29PM

It is very much like what siria said. A full automatic method just is not available. It is possible to have a two step version. You first open background tabs for each item. Then you go to the menu for a second item which will save each to file. Also you must complete the "save as" information for each file. I hope this will be of some use.

DLS.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage2)
#
# ---------- DLS.kmm
#
# Dependencies        : main.kmm
# Resources           : -  
# Preferences         : "k-meleon_DLS_use"
# Version             : .4  
# --------------------------------------------------------------------------------

_DLS_download {
	$linkIdx = "http://kmeleon.sourceforge.net/gfx/shot";;
	$ext = ".png";
	$i=3;
	$c=1;
	$_DLS_sc=0;
	while($i<5) {
		openbgtab( $linkIdx . $i . $ext );
		macros("_DLS_assignurl");
		setpref( INT , "k-meleon_DLS_use", $c );
		$i = $i+1; $c = $c+1 ;
	}
}

_DLS_assignurl {
	$i==1 ? $DLS_url_1 = $linkIdx . $i . $ext : 0;
	$i==2 ? $DLS_url_2 = $linkIdx . $i . $ext : 0;
	$i==3 ? $DLS_url_3 = $linkIdx . $i . $ext : 0;
	$i==4 ? $DLS_url_4 = $linkIdx . $i . $ext : 0;
	$i==5 ? $DLS_url_5 = $linkIdx . $i . $ext : 0;
	$i==6 ? $DLS_url_6 = $linkIdx . $i . $ext : 0;	
	$i==7 ? $DLS_url_7 = $linkIdx . $i . $ext : 0;	
	$i==8 ? $DLS_url_8 = $linkIdx . $i . $ext : 0;
	$i==9 ? $DLS_url_9 = $linkIdx . $i . $ext : 0;	
}

_DLS_status {
$_DLS_sc = $_DLS_sc + 1;
statusbar("pages loaded = " . $_DLS_sc);

} 

_DLS_save {
$_DLS_cc = getpref(INT,"k-meleon_DLS_use");
while( $_DLS_cc > 0) {
	id(ID_TAB_NEXT) ;
	if ( $URL == $DLS_url_1 ) {	id(ID_FILE_SAVE_AS); $DLS_url_1 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_2 ) { id(ID_FILE_SAVE_AS); $DLS_url_2 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_3 ) { id(ID_FILE_SAVE_AS); $DLS_url_3 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_4 ) { id(ID_FILE_SAVE_AS); $DLS_url_4 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_5 ) { id(ID_FILE_SAVE_AS); $DLS_url_5 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_6 ) { id(ID_FILE_SAVE_AS); $DLS_url_6 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_7 ) { id(ID_FILE_SAVE_AS); $DLS_url_7 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_8 ) { id(ID_FILE_SAVE_AS); $DLS_url_8 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_9 ) { id(ID_FILE_SAVE_AS); $DLS_url_9 = "";  $_DLS_cc = $_DLS_cc-1; }
	}
setpref(INT,"k-meleon_DLS_use",0);
}

_DLS_BuildMenu{
setmenu("&Tools",macro,"DLS-Get",_DLS_download,Misc);
setmenu("&Tools",macro,"DLS-Save",_DLS_save,Misc);
$_DLS_sc=0;
}

$OnLoad=$OnLoad."_DLS_status;";
$OnInit=$OnInit."_DLS_BuildMenu;";


Options: ReplyQuote
Re: Problem with download macro
Posted by: siria
Date: March 13, 2011 10:11PM

Forgot to mention, regarding that save-dialogue: There's an old pref that is now finally accessible in the pref sheets in desga's beta version smiling smiley In F2>Browsing>File Handling
That toggles a pref named... too tired to look up right now, guess something with savedir in the name...
It makes that the command file_save_as does NOT pop up the dialogue but just dumps the file into the last used folder - if I remember right... better check again yourself.
That (in the past) hidden pref had given me a lot of headaches too, couldn't figure out for a long while why that save-box suddenly and unexpectedly had vanished some day!! ;-) And beware of browser crashes, if you toggle that pref with a macro, and intend to toggle it back at exit automatically...

Options: ReplyQuote
Re: Problem with download macro
Posted by: JamesD
Date: March 13, 2011 10:53PM

@ siria

Yes, I think that pref is "kmeleon.download.useSaveDir". If it set to TRUE then the save goes automaticly to location indicated in the pref "kmeleon.download.saveDir". I hope I have these right.

If I was writing a complete macro, then maybe I would check "kmeleon.download.saveDir" for the location and set "kmeleon.download.useSaveDir" to true. Of course I would have to maintain the original values and reset them when finished. I am not sure how ra plans to obtain his value for the pages to load. The example is hard coded.

Edit:
I think I am wrong about which perf to use. Still checking.



Edited 1 time(s). Last edit at 03/13/2011 11:17PM by JamesD.

Options: ReplyQuote
Re: Problem with download macro
Posted by: JamesD
Date: March 14, 2011 02:58AM

Well I have updated code. It works as long as I do not reset the pref. The two "saves" take too much time and the pref is reset to false before all the action finished, I guess. Feel free to try out the code and make changes if needed. One other minor change was added at line 63.

Edit: This code updated to version = .6 because of a timing problem. I have fast processor but a standard speed drive. I had to put an alert to allow the file saves to finish before resetting the pref to false.

DLS.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage2)
#
# ---------- DLS.kmm
#
# Dependencies        : main.kmm
# Resources           : -  
# Preferences         : "k-meleon_DLS_use"
# Version             : .6  
# --------------------------------------------------------------------------------

_DLS_download {
	$linkIdx = "http://kmeleon.sourceforge.net/gfx/shot";;
	$ext = ".png";
	$i=3;
	$c=1;
	$_DLS_sc=0;
	while($i<5) {
		openbgtab( $linkIdx . $i . $ext );
		macros("_DLS_assignurl");
		setpref( INT , "k-meleon_DLS_use", $c );
		$i = $i+1; $c = $c+1 ;
	}
}

_DLS_assignurl {
	$i==1 ? $DLS_url_1 = $linkIdx . $i . $ext : 0;
	$i==2 ? $DLS_url_2 = $linkIdx . $i . $ext : 0;
	$i==3 ? $DLS_url_3 = $linkIdx . $i . $ext : 0;
	$i==4 ? $DLS_url_4 = $linkIdx . $i . $ext : 0;
	$i==5 ? $DLS_url_5 = $linkIdx . $i . $ext : 0;
	$i==6 ? $DLS_url_6 = $linkIdx . $i . $ext : 0;	
	$i==7 ? $DLS_url_7 = $linkIdx . $i . $ext : 0;	
	$i==8 ? $DLS_url_8 = $linkIdx . $i . $ext : 0;
	$i==9 ? $DLS_url_9 = $linkIdx . $i . $ext : 0;	
}

_DLS_status {
if (getpref(INT,"k-meleon_DLS_use") > 0 ) {
	$_DLS_sc = $_DLS_sc + 1;
	statusbar("pages loaded = " . $_DLS_sc);
	}
} 

_DLS_save {
$_DLS_cc = getpref(INT,"k-meleon_DLS_use");
setpref(BOOL, "kmeleon.download.useSaveDir", true) ;
while( $_DLS_cc > 0) {
	id(ID_TAB_NEXT) ;
	if ( $URL == $DLS_url_1 ) { id(ID_FILE_SAVE_AS); $DLS_url_1 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_2 ) { id(ID_FILE_SAVE_AS); $DLS_url_2 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_3 ) { id(ID_FILE_SAVE_AS); $DLS_url_3 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_4 ) { id(ID_FILE_SAVE_AS); $DLS_url_4 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_5 ) { id(ID_FILE_SAVE_AS); $DLS_url_5 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_6 ) { id(ID_FILE_SAVE_AS); $DLS_url_6 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_7 ) { id(ID_FILE_SAVE_AS); $DLS_url_7 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_8 ) { id(ID_FILE_SAVE_AS); $DLS_url_8 = "";  $_DLS_cc = $_DLS_cc-1; }
	if ( $URL == $DLS_url_9 ) { id(ID_FILE_SAVE_AS); $DLS_url_9 = "";  $_DLS_cc = $_DLS_cc-1; }
	}
setpref(INT,"k-meleon_DLS_use",0);
alert( "save to drive completion","Planned wait for",INFO);
setpref(BOOL, "kmeleon.download.useSaveDir", false) ;
$_DLS_sc = 0 ;
}

_DLS_BuildMenu{
setmenu("&Tools",macro,"DLS-Get",_DLS_download,Misc);
setmenu("&Tools",macro,"DLS-Save",_DLS_save,Misc);
$_DLS_sc=0;
}

$OnLoad=$OnLoad."_DLS_status;";
$OnInit=$OnInit."_DLS_BuildMenu;";



Edited 1 time(s). Last edit at 03/14/2011 12:56PM by JamesD.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.