Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Search wikipedia from the command line UNIX
I am probably not the only one to be overcome with the delights and wonders of wikipedia.org. However, searching my favourite encyclopaedia is a bit of a chore. The wikipedia.org main page is slow at the best of times. I'd rather have something like my google bar that would allow me to type in a query (XFS, for example) and then boom!, up comes a page telling me all about XFS. So I wrote a script that does exactly that:
#!/bin/bash
open http://en.wikipedia.org/wiki/Special:\
Search?search=$(echo $@ | sed 's/\ /+/g')
After saving that to a file (I called mine wikipedia) and running chmod 755 wikipedia to make it executable, place it in your command path (I use ~/bin). Now all you have to do to search for wikipedia entries with references to dogs with pockets is go to the terminal and type:
$ wikipedia dogs with pockets
You can probably think of more useful things to search for...

[robg adds: I broke the script's one line of code into two to make it narrower for display here. The backslash should let you copy and paste it, and it will work just fine. If this bothers your sense of aesthetics, though, just remove the backslash and the line break. Do not put a space between the : and the S.]
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[9,320 views]  

Search wikipedia from the command line | 16 comments | Create New Account
Click here to return to the 'Search wikipedia from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Search wikipedia from the command line
Authored by: ms_t_rie on Dec 06, '04 10:21:27AM

If you don't like the command line and use the Firebox browser, Wikipedia is one of the engines that can be added to the search box. Dogpile is what I usually use, but switching which engine is as simple as picking the one to use from the dropdown, then typing in what to search for. Adding Wikipedia and Dogpile to the list is simple enough, just select Add Engines from the dropdown, it takes you right to a page with them listed. Click on the one to add and it prompts you to add it to the list. Very handy! (and another reason I use Firebox instead of Safari)



[ Reply to This | # ]
Search wikipedia from the command line
Authored by: guybrush on Dec 06, '04 11:33:27AM

I suggest you use Saft in Safari, and then make a shortcut for wikipedia, so you can type something like this in your address bar:

wikipedia XFS

saves you launching a terminal :)



[ Reply to This | # ]
Search wikipedia from the command line
Authored by: LoonyPandora on Dec 07, '04 04:13:33AM
Personally, I use AcidSearch, and add wikipedia in there.

AcidSearch is a former PoTW, and works like a charm for me. One of the reasons I love visiting here, great PoTW's ;)

[ Reply to This | # ]
Search wikipedia from the command line
Authored by: sjk on Dec 07, '04 09:00:47PM
Sogudi and SafariStand are donation and freeware alternatives to Saft for adding quick search shortcuts to Safari. Some of Saft's other features made it worth paying the shareware fee. And keep your order number to minimize hassles downloading updates if you buy it.

Oh, just noticed Sogudi's already been mentioned. Anyway...

[ Reply to This | # ]
Search wikipedia from the command line
Authored by: Anonymous on Dec 10, '04 11:37:17AM
saves you launching a terminal

Do you mean to say that folks run OS X (or Windows, for that matter) without a POSIX shell running all the time? How do you get anything done?

Jeepers, I even have several saved Terminal sessions, with my default running at least two sessions in different colours. I haven't yet made this a startup item. Yet.

[ Reply to This | # ]

Search wikipedia using Saft context menu.
Authored by: KirbyK on Feb 17, '05 09:09:48AM

It's easy, but it's not so easy that "make a shortcut and type something in your address bar" is going to suffice for non-programers. Here's what worked for me:

Under Safari>Preferences>Saft>Shortcuts add the following for Name, Shortcut, and URL:

Wikipedia
Wiki
http://en.wikipedia.org/wiki/Special:Search?search=%@&go=Go

(The trick there was to get Wikipedia to accept multiple word selections.)

I find Answers.com saves me some time and I like having one link instead of several. It includes a dictionary, thesaurus, *and* Wikipedia.

Add a Saft shortcut as above, using:

Answers
A
http://www.answers.com/%@

Each works on text selected in Safari. Each should work from the address bar.



[ Reply to This | # ]
Solution with no additives
Authored by: trekan on Dec 06, '04 12:38:16PM
I use a modification of a bookmarklet I found here on MacOSXHints:

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('What%20should%20I%20look%20up?',''))%7D;window.location='http://en.wikipedia.org/wiki/Special:Search?search='+x+'&go=Go'

Just select this and drag it to your Safari (or FireFox?) toolbar. If you select a word and click the bookmark, it will search for that word (or expression), else it will ask you for a search word.

[ Reply to This | # ]
iWiki - another solution
Authored by: brass monkey on Dec 06, '04 02:02:19PM

Another free non-command line solution is iWiki - uses hotkeys to search with the current selection or via a dialog:

http://web.ticino.com/galliva/iwiki/



[ Reply to This | # ]
Search wikipedia from the command line
Authored by: Paul Burney on Dec 06, '04 02:06:54PM
In Mozilla, you can do a search on wikipedia, then go to Bookmarks -> File Bookmark. Add a keyword in the keyword field (I use "w"). Replace your search term with a %s. Now I can type this in the URL bar:
w they might be giants
To get wikipedia to search for, and bring me to, their page about the two Johns.

[ Reply to This | # ]
Quicksilver version
Authored by: drauh on Dec 06, '04 03:20:58PM

Add the following as a bookmark in Safari, in the Quicksilver bookmark folder:

qss-http://en.wikipedia.org/wiki/Special:Search?search=***&go=Go



[ Reply to This | # ]
Search wikipedia from the command line
Authored by: Treavize on Dec 06, '04 03:49:25PM

This looks like a wonderful and useful tool. I followed the instructions to the letter and this is not working for me. I am using the tcsh shell, so that may be the problem. I tried to run the script also in the bash shell and still no go. Any ideas on whats wrong here?

---
Sage iMac DV+ 450MHz G3 Slotloader, 768mb, 80gig, OS X 10.3



[ Reply to This | # ]
Search wikipedia from the command line
Authored by: SOX on Dec 06, '04 04:02:02PM

did you put he location of the command in your path. if not type the path explicity.



[ Reply to This | # ]
Search wikipedia from the command line
Authored by: Treavize on Dec 06, '04 04:15:42PM

Never mind. I have the script working now. I didn't have my path set correctly.

---
Sage iMac DV+ 450MHz G3 Slotloader, 768mb, 80gig, OS X 10.3



[ Reply to This | # ]
Search wikipedia from the command line
Authored by: Hodag on Dec 06, '04 04:24:50PM
What about Sogudi? http://www.atamadison.com/w/kitzkikz.php?page=Sogudi

---
--
Adam C.

[ Reply to This | # ]

Launchbar users have this already
Authored by: TallDwarf on Dec 06, '04 07:37:40PM

If you have Launchbar 4 it is prebuilit in as a search template. I prefer launchbar to saft or sugoudi as it is launched universally

Command+space for launchbar --> wiki --> [space] + whatever you want to look for.



[ Reply to This | # ]
Search wikipedia from the command line
Authored by: svanstrom on Dec 07, '04 09:05:02AM

For the past cpl of years I've been using this quick hack to search some sites (Macosxhints, Google [mostly pre Safari], wikipedia etc); you only have to change one line to make it work with other sites.

I use the same ones on my Mac and on other OS:es; the code aint pretty, but it works the way _I_ want it to. =)

#!/usr/bin/perl -w
# 2002 © svanstrom.com - all rights reserved
# <URL: http://www.svanstrom.com >

foreach (@ARGV) {$_ = "\"$_\"" if /\s/};

($q = "@ARGV") =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
$q = "http://en.wikipedia.org/wiki/Special:Search?search=$q";

if (! exists $ENV{REMOTEHOST} && $ENV{OSTYPE} eq 'darwin') {
        print <<'END'

I hope you'll find it! =)

        /tony@svanstrom.com
<URL: http://www.svanstrom.com/ >

END
;
        system('open', $q)
} else {
        system("lynx", "$q");
        print <<'END'

I hope you found it! =)

        /tony@svanstrom.com
<URL: http://www.svanstrom.com/ >

END
;
}

---
--


[ Reply to This | # ]