2

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?

1 Answer 1

5
+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)
3
  • I wanted to award You - but did something wrong. I'll award You at the end of the bounty.
    – Adobe
    Apr 6, 2012 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?
    – Sathyajith Bhat
    Apr 6, 2012 at 8:14
  • @Adobe Thanks, glad it helped. Pentadactyl is a fantastic piece of software.
    – ngm
    Apr 6, 2012 at 19:53

You must log in to answer this question.

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