On Tue, Jun 01, 2010 at 12:02:34PM +0200, Łukasz Michalik wrote:
> On 00:13 2010-06-01 -0700, andrew mcintosh wrote:
> > Is there some way to set the default save location of a file based on the 
> > mime type?
> > 
> > For example, I'd like to save all my .torrent files automatically to 
> > ~/rtorrent/tracker.
> > 
> 
> What I am doing, and what is probably overcomplicated, but should work
> for you too.  First setting external handler for that mime in
> .conkerorrc:
> 
> external_content_handlers.set("application/x-bittorrent", "torrent-launcher");
> content_handlers.set("application/x-bittorrent", 
> content_handler_open_default_viewer);
> 
> Whereas torrent-launcher is an executable script in PATH which does
> what it supposed to do on a given host.  For simple case as yours it
> would probably suffice to put
> 
> #!/bin/sh
> mv "$1" ~/rtorrent/tracker
> 
> in it.


Another way would be to override the function
suggest_save_path_from_file_name with one that sets the directory based on
the file extension passed to it.  If you did this, you would still be
prompted for a filename to save to, but its default location would be the
one you want.

///// untested code:
function suggest_save_path_from_file_name (file_name, buffer) {
    var file;
    if (/\.torrent$/.test(file_name)) {
        file = get_home_directory();
        file.appendRelativePath("rtorrent/tracker");
    } else {
        file = with_current_buffer(buffer, function (I) I.local.cwd)
            .clone();
    }
    file.append(file_name);
    return file.path;
}


To get even more automation, for instance if you wanted to eliminate
prompts altogether, you could use content handlers.  See
http://conkeror.org/ContentHandlers for that.

-- 
John Foerch
_______________________________________________
Conkeror mailing list
Conkeror@mozdev.org
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to