I've created a service to use primarily in a browser for searching IMDB, so instead of copying and pasting the film's name I just select the text and run the service I created which will automatically search IMDB for the selected text. This works perfect.

enter image description here

I was hoping to do the same for Wikipedia and so i've been trying to modify the same service but have come across a problem. The search query places a "+" between each word.

This doesn't work for Wikipedia. They place underscores between their words.

enter image description here

I wondered how I can substitute the + for _? This is what I currently have

open "https://en.wikipedia.org/wiki/$(ruby -rcgi -e 'print CGI.escape $<.read.chomp')"

Kinds regards and Merry Christmas :)


WikiPedia places underscores for its entry URLs, but you can search any string (actually with spaces) with this URL scheme:


Replace [query] with you search query.

Try this for example: Search for "stack overflow"

It redirects to correct page. If it can't determine which entry to show, it shows a list of possible entries you can select from: Search for "stack overfloww".


Moreover, if you separate words in query with +, it works just fine. So all you need to do is replace

open "https://en.wikipedia.org/wiki/$(ruby -rcgi -e 'print CGI.escape $<.read.chomp')"

with this:

open "https://en.wikipedia.org/w/index.php?search=$(ruby -rcgi -e 'print CGI.escape $<.read.chomp')"
  • @Frasier013 Since we're on the subject, this is a great Safari extension for searching in different sites from the address bar. Since you're using El Capitan, follow the first post here to install it in case you ran into problems.
    – Behdad
    Dec 24 '15 at 20:10
  • Thanks buddy, i'll check out that extension. Appreciate the help!
    – Frasier013
    Dec 24 '15 at 20:13
open "https://en.wikipedia.org/wiki/$(ruby -rcgi -e 'print CGI.escape $<.read.chomp' | sed 's/+/_/g')"

sed 's/+/_/g' replaces all instances of + with _


You must log in to answer this question.

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