Map keys in lynx to run shell-command

Go To


Is it possible to add a custom keymap to lynx (in the config file ~/.lynxrc), which sends information (e.g. the current URL, html, title, etc.) to a shell command?

An example use case: I am on OSX and the shell has a command open, which attempts to open anything given to it in a default fashion. So, if I am in lynx and want to move the current webpage to the default browser I would want to call open current-url from the shell.

Another: Collating an organized bookmark file by sending URL and title to a shell script (or something else).

Using the default keymap ! opens up the default shell, but it doesn't give me the URL nor does it run a single command and exit back to lynx as I would want for this.

Any ideas would be greatly appreciated.

2012-04-04 05:04
by scicalculator


I actually ended up finding a couple ways to handle this. Some are more ideal than others. It took some digging through the default lynx.cfg file to figure some of this out.

The following are the two most successful ways I accomplished sending info to a shell command from lynx:

  1. place a variation of this in your lynx.cfg file. It can only send the URL, so it is limited by not being able to handle the title or any other information from the webpage without parsing a lynx dump itself. (This must be configured with --enable-extern, which is not available with MacPorts version of lynx, so you gotta install from source).

    # in lynx.cfg
    # EXTERNAL:<url>:<command> %s:<norestriction>:<allow_for_activate>[:environment]
    # Ex 1: send the url to `open <url>` to open default browser
    EXTERNAL:http:open %s:TRUE
    # Ex 2: download with wget if ftp page
    EXTERNAL:ftp:wget %s &:TRUE
    # By default ',' and '.' map to running EXTERNAL on the page and link respectively
    # KEYMAP:,:EXTERN_PAGE   # Run external program with current page
    # KEYMAP:.:EXTERN_LINK   # Run external program with current link
  2. Create a script and run it with printer to collect print environment variables.

    # in lynx.cfg
    # PRINTER:<name>:<command>:<option>:<lines/page>[:<environment>]
    PRINTER:openurl:/Users/username/bin/openurl %s:TRUE 

    Then the script openurl, which opens the url in a default browser (OSX) contains:

    # /Users/username/bin/openurl
    # other variables exist like the date etc... look them up :)
    # perform magic ...
    /usr/bin/open $url

There may be other ways like using the lynxified proxies lynxexec, lynxprog, and lynxcgi, but I was unable to successfully pass variables with these methods in my own tests. If you know a way to get title and url information from these methods I would be interested in hearing it. The example #1 above could essentially grab the title and other information by invoking lynx or some other browser, so it is essentially possible to get everything done with that method. Also, it allows a single key mapped to perform the function, which the print screen adds several keystrokes to the mix, which is undesirable. I recommend #1 above.

2012-04-05 01:23
by scicalculator