Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Using the Linux command line (Bash shell) I like to load a specific website in my browser (normally Firefox, but other one would be ok as well as long it runs under Linux) and fill a pre-defined form with some data. Actually, this should run from a Makefile. Most of the form data is static and will be stored as variables in the Makefile, just some fields are to be filled manually before manually sending the form.

I know how to load the website in question from the command line using:

firefox <URL>

But there seems no possibility to fill the form automatically with variables given on the command line. Is there a plugin, executable or JavaScript which allows me to do this? Any suggestions and hints are welcome. I don't mind coding some JavaScript.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

See https://github.com/bard/mozrepl/wiki. MozRepl lets you connect via telnet, in combination with netcat this would be exactly what you need.

share|improve this answer
    
Thanks. Is the browser still opened as normal? Like I said I want to make final edits and submit it manually. –  Martin Scharrer Mar 19 '11 at 22:31
    
Yes, once you've started firefox normally you are able to telnet into it. –  artistoex Mar 19 '11 at 22:33
    
Thanks. This brought me now to the idea that I can solve this also using a user script, which is simpler (see my own answer). I will accept your answer after a short while. –  Martin Scharrer Mar 24 '11 at 23:52
add comment

I solved this now using a Greasemonkey script which copies the URL parameters to the form. The Makefile calls firefox with the URL including the parameters.

This works for my needs. Some refinements would be needed for more complex input, i.e. some URL encoding.

User Script:

// ==UserScript==
// @name           Fill CTAN upload form
// @namespace      http://www.scharrer-online.de/namespace/
// @description    Fills the CTAN upload form with the data provided as URL variables
// @include        http://*.ctan.org/upload.html*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==

//var $ = unsafeWindow.jQuery;

// From http://papermashup.com/read-url-get-variables-withjavascript/
// Added: decodeURI
function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = decodeURI(value);
    });
    return vars;
}

var vars = getUrlVars();

for (name in vars) {
    $("input[name=" + name + "]").val(vars[name]);
    $("select[name=" + name + "]").find("option:selected").removeAttr('selected');
    $("select[name=" + name + "]").find("option[value=" + vars[name] + "]")
            .attr('selected','selected');
}

if ('DoNotAnnounce' in vars) {
    var val = vars['DoNotAnnounce'].toLowerCase();
    if (val == '1' || val == 'yes' || val == 'true') {
        $("input[name=DoNotAnnounce]").attr('checked','checked');
    }
}

Makefile:

# CTAN Upload
CTAN=http://dante.ctan.org/upload.html
CONTRIBUTION=filemod
VERSION=
NAME=John Doe
EMAIL=john.doe@somewhere.com
SUMMARY=Updated to ${VERSION}:
DIRECTORY=/macros/latex/contrib/${CONTRIBUTION}
DONOTANNOUNCE=
ANNOUNCEMENT=
NOTES=
LICENCE=free
FREEVERSION=lppl
#FILE= # can't be set because of security limitations

upload: ctanify
    firefox 'http://dante.ctan.org/upload.html?contribution=${CONTRIBUTION}&version=${VERSION}&name=${NAME}&email=${EMAIL}&summary=${SUMMARY}&directory=${DIRECTORY}&DoNotAnnounce=${DONOTANNOUNCE}&announce=${ANNOUNCEMENT}&notes=${NOTES}&license=${LICENCE}&freeversion=${FREEVERSION}' &
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.