Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider a problem of searching several wikis at one command. Here's a possible solution. If one'd add the following to the .pentadactylrc:

javascript <<EOF
    dactyl.searchWikis = function (selection) {
        let parsedSelection = selection.replace(/^\s*/, "" ).replace(/\s*$/, "" ).replace(/\s+/g, "+" );
        dactyl.execute( ":tabopen http://www.scholarpedia.org/wiki/index.php?title=Special:Search&search=" + selection);
        dactyl.execute( ":tabopen http://en.citizendium.org/wiki?title=Special:Search&search=" + selection);
    };
EOF

:command wikiSearch -nargs=* -js dactyl.searchWikis(<args>)

That should've solved it - but the problem is - that this way Pentadactyl doesn't see the JS code. I.e. new command wikiSearch doesn't appear. Can You fix it?

share|improve this question
up vote 6 down vote accepted
+50

I believe you need to add your function on the userContext, rather than on dactyl.

e.g.

javascript <<EOF
    userContext.searchWikis = function (selection) {
        commands.execute("tabopen http://www.scholarpedia.org/wiki/index.php?title=Special:Search&search=" + selection);
        commands.execute("tabopen http://en.citizendium.org/wiki?title=Special:Search&search=" + selection);
    };
EOF

I took the parsedSelection line out, as selection doesn't appear to come in as a string.

Also try removing the angle-brackets from <args>:

command wikiSearch -nargs=* -js userContext.searchWikis(args)
share|improve this answer
    
I wanted to award You - but did something wrong. I'll award You at the end of the bounty. – Adobe Apr 6 '12 at 7:39
    
@Adobe that's how bounties work. you start a bounty, you can award the amount after 2 days of starting the bounty. How does the bounty system work? – Sathya Apr 6 '12 at 8:14
    
@Adobe Thanks, glad it helped. Pentadactyl is a fantastic piece of software. – ngm Apr 6 '12 at 19:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .