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

Change Safari's default search engine - revisited Web Browsers
This hint describes a way of changing Safari's default search engine. Unlike the method which was posted a couple of days ago, this method does not block normal access to google.com. This hint assumes you are familiar with the vi text editor. First, quit Safari and make a backup copy of the application. Then follow these steps:
  1. Launch Terminal, and use the vi editor to open the Safari executable file. The command will probably look like this for most users:
     % vi /Applications/Safari.app/Contents/MacOS/Safari
    
  2. Search for the text google. The first occurrence will be a string that looks like this:
     http://%@.google.com/%@?q=%@&ie=UTF-8&oe=UTF-8
    
    This is the string that needs to be modified.

  3. Change the string to the search engine you'd like to use. When changing this string, two things need to be kept in mind. First, the length of the new string must be the exact same length as the original. Second, you need to have two %@ sequences in the string. The second %@ should represent where your "query" would go in the URL. Here is an example. To make Yahoo! the default search engine, replace the string:
     http://%@.google.com/%@?q=%@&ie=UTF-8&oe=UTF-8
    
    with:
     http://%@@search.yahoo.com/bin/search?p=%@&a=0
    
    The way I figured this out was by performing a search at yahoo.com for "apple". The URL of the results page was:
     http://search.yahoo.com/bin/search?p=apple
    
    So to keep my length constant, I needed to expand the string a little. I added a %@@ at the beginning of the URL. Putting "something@" at the beginning of a URL will not affect the loading of a site. This allowed me to take care of the first %@ sequence I needed to retain. Then I replaced apple with another %@. This is obviously where my 'query' fits into the URL. Finally, I needed to add a bogus (unused) form field to the URL, so that the string would be the correct length. I added &a=0. So if you take a look at the original string, and the new one, the lengths of both strings are identical, as seen above.

  4. Save your changes and quit the editor.
The next time you use Safari's search box, your favorite search engine will be used. Note that if the string you enter is not of the correct length, Safari will fail to launch.
    •    
  • Currently 2.50 / 5
  You rated: 2 / 5 (30 votes cast)
 
[271,151 views]  

Change Safari's default search engine - revisited | 46 comments | Create New Account
Click here to return to the 'Change Safari's default search engine - revisited' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Change Safari's default search engine - revisited
Authored by: aranor on May 16, '03 04:59:36PM

Unfortunately, there are those of us who don't know how to use vi. Any suggestions on an alternative editor? I tried pico, but for some reason it couldn't find that when searching for google, it only found the text ShowGoogle



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: dice on May 16, '03 06:02:38PM

You don't need to use the terminal at all....

Find Safari and make a backup, then show package contents and find the folder MacOS.

The file called Safari in this folder is the one you want to edit, you can simply drag this onto BBedit or textedit or whatever and search (cmd-f) for
http://%@.google.com/%@?q=%@&ie=UTF-8&oe=UTF-8

then follow the rest of the original hint... :)



[ Reply to This | # ]
Thank you Dice
Authored by: bogdescu on May 16, '03 06:04:15PM

--- very much!



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: bogdescu on May 16, '03 06:03:02PM

I second aranor's request - what about BBedit? BTW, thank you for this wonderful hint!



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: kuikeelc on Jul 23, '03 04:44:00AM
If you want to do it more easy than this, try this plugin for the Mozilla/Phoenix browser:

http://needlesearch.mozdev.org

It finds out how a search engine works and then adds it to a search engine bookmark list.

Regards,

Eelco


[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: aranor on Feb 20, '04 02:06:25AM

What, you're suggesting as an alternative to modifying Safari's search engine (something I don't have any desire to do, but is still interesting) is to switch browsers completely? Sheesh



[ Reply to This | # ]
How about for AllTheWeb???
Authored by: jiclark on May 16, '03 09:12:58PM

I've tried to make the string work for alltheweb.com, with no success. It's a fair bit longer than the google one... Could someone who's done this for alltheweb.com please post the string they used to do it?

BTW, I was using BBEdit, and don't know if I messed something up, but even when I pasted the original string back in, Safari wouldn't launch. Good thing I had a backup!

Thx,
John

---



[ Reply to This | # ]
AllTheWeb and Teoma
Authored by: vasi on May 16, '03 10:18:04PM
Here are some other useful search strings:

  • For AllTheWeb:
    http://%@.alltheweb.com/%@?q=%@&ie=UTF-8&z=F-8
  • For Teoma:
    http://%@:@s.teoma.com/%@?q=%@&ie=UTF-8&z=TF-8

Also, I recommend use of HexEdit for editing the Safari binary.

vasi

[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: jeremyrh on May 17, '03 11:52:10AM

That looks great, but ....
what do you do when you want to use a search engine with a LONGER string, e.g. google.co.uk instead of google.com? Any ideas?



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: jeremyrh on May 19, '03 04:04:21AM

To answer my own question:
http://%@.google.co.uk/%@?q=%@&ie=UTF-8&z=TF-8

This works, but what is the significance of changing the last "oe=UTF-8" to "z=TF-8" ??



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: gavinh on Jun 24, '03 06:54:19AM

My way of getting round this is to use one line of PHP code and the webserver installed as standard on OS X!
If you want to give it a try this is what you have to do (all of this is easiest done in Terminal):

1. Create a directory in your webservers root by typing:

mkdir /Library/WebServer/Documents/www

2. Create your PHP script by doing the following:

vi /Library/WebServer/Documents/www/search.php

3. While the file is open in your terminal window push the 'i' key on your keyboard (this puts you into Insert mode so that you can type into the file). Now type the following:

<?php header("Location: http://www.google.co.uk/search?hl=en&ie=ISO-8859-1&q=".$search."&btnG=Google+Search&meta=cr%3DcountryUK%7CcountryGB"); ?>

4. Be aware that the above line of code must be on a single line and not over several lines! Once you have typed this in hit the 'esc' or Escape key to come out of Insert mode. Now type:

:wq!

5. And hit the Return or Enter key. (For those that don't know ':wq!' is the command to Write the file and Quit Vi)

6. Now you need to edit the Safari executable. Type:

vi /Applications/Safari.app/Contents/MacOS/Safari

7. Once the file is open in your teminal window to search for the entry to be deleted type:

/google.com

8. You will be taken to the piece of code that contains 'http://%@.google.com/%@?q=%@&ie=UTF-8&oe=UTF-8'. You need to replace this piece of code. To do this use the 'x' key on your keyboard to delete, then hit the 'i' key again to go in to Insert mode and type:

http://localhost/%@/%@.php?search=%@&000000000

9. Hit the 'esc' or Escape key and then type:

:wq!

10. And hit the Return or Enter key.

Thats it! To explain what we've done, the Safari executable now looks at a script on your local machine which then redirects to the correct search engine. I have used '&000000000' to pad out the line as mentioned in an earlier post as the entry must be the same length as the original.

I hope this is of some use to people.



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: aranor on Feb 20, '04 02:08:26AM

Ah, but that depends on register globals being turned on. Try using $_GET['search'] instead of $search



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: arumdevil on Apr 11, '06 04:10:16AM
you can paste in the following to use google.co.uk as the search engine. note that this will still search the entire web rather thanm UK sites only:
http://%@@google.co.uk/search?hl=en&q=%@&meta=
a

[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: smoothy.boothy on May 08, '06 11:36:50AM

When i try that and i perform a search, no matter what i type it just searches search! Very annoying. Does anybody know how to fix it?



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: Yennick on Nov 24, '09 06:28:33AM

add an extra %@ instead of the text "search" in the URL



[ Reply to This | # ]
Okay, now that we've accomplished this...
Authored by: jiclark on May 19, '03 02:51:38AM

...how does one change the pale gray text in the Search area of the Toolbar from 'Google' to 'AllTheWeb' or 'Teoma'???

Is it even possible?

Thanks,
John-o

---



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: el bid on May 19, '03 09:25:36AM

It's unbelieveably dumb of Apple to have hard-wired the search engine into the code like this. This isn't a thing that sane programmers do, unless they have a marketing person on top of them with a knee in their groin.

WFT is going on here???



---
--
el bid



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: sylvank on Jul 23, '03 12:32:02PM

I agree; at the very least it should be in an internal plist or something. Compiled into the binary!? I suppose they thought they could stop us from editing it! :-P



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: rschwarz on Mar 23, '06 07:38:53AM

I think that apple has some kind of a deal with google. So they are not really interested in having users change this.



[ Reply to This | # ]
As long as we're messing with the code...
Authored by: jiclark on May 20, '03 01:30:11AM
Does anyone have an idea of how one would go about changing the pale gray text in the search bar to say the name of the site you've changed it to, instead of "Google"? Shouldn't be that hard, considering that it wasn't too easy to change the search engine!!! thanks, John-o

---


[ Reply to This | # ]

Changing the gray text in the search box...
Authored by: davidpc on May 20, '03 03:12:40PM

The text that appears in the search box is stored in:

Safari.app/Resources/English.lproj/Localizable.strings

Open that file in any text editor, do a find for "Google," and you'll see a line like:
"Google" = "Google"

Change the second Google to whatever you'd like displayed, like:
"Google" = "Yahoo"

Save the file, and (re)launch Safari.



[ Reply to This | # ]
Changing the gray text in the search box...
Authored by: j0hnE5 on Feb 20, '04 01:55:06AM

I was only able to change the context menu, the accessibility description and the 'no search text' message box by editing the Localizable.strings file.

To change the gray text I used Interface Builder to modify Browser.nib, found in /Applications/Safari/Content/Resources/English.lproj/.

Simply select the search box, the choose Tools->Show Info from the menu, then choose Attributes in the info window's pull down menu and from there you can change 'Google' to whatever you like.



[ Reply to This | # ]
Changing the gray text in the search box...
Authored by: hyperion on May 04, '12 08:10:39PM

I tried to do this [Safari Version 5.1.5 (7534.55.3)], but when I open Browser.nib in Xcode Version 4.3.2 (4E2002), all I get is a file icon. Nothing shows up. I am clueless. Searched on the web for hints but I couldn't find anything.



[ Reply to This | # ]
Still doesn't work
Authored by: jason mark on May 25, '03 09:56:23AM

I don't have BB Edit, so I tried thsi with Text edit 3 times, I also tried it with emacs, and with word.

EVERY time the safari application won't run after my change. Any advice?



[ Reply to This | # ]
GOT IT! - Hexedit
Authored by: jason mark on May 25, '03 10:11:10AM

After reading through some old commentions the original hint I decided to try one last application to try to make this update (Hexedit).

It worked!

I'll admit the problem all along could have easily been User Error, but Hexedit makes it very easy to see every character, and change it by hand without (for instance) accidently removing one of the two spaces after the URL..



[ Reply to This | # ]
Error in Original Post for Yahoo Search
Authored by: Porter on Jun 06, '03 04:50:29PM
I've found an error in the original post. There should be three %@'s in the URL. The first inserts a "www", the second inserts the word "search" and the third inserts the actual search string. The original modifcation

http://%@@search.yahoo.com/bin/search?p=%@&a=0

Always inserts the word 'search' where the actual query should go. Here is a replacement string:

http://%@@search.yahoo.com/%@?p=%@&blankspot=0

This will give you a URL something like:

http://www@search.yahoo.com/search?p=mySearch&blankspot=0

I've highlighted the places where the %@ gets replaced with text in bold. I'd also like to register my own confusion as to why Apple hard-coded this. It sure seems like a nice feature for Safari's Preference pane to me.

[ Reply to This | # ]
A Hybrid Approach
Authored by: tbreihol on Jul 02, '03 09:01:24PM

I combined this tip with the previous tip that used /etc/hosts in the following way. I wanted to use AllTheWeb, but didn't want to worry about the size of the string, so I changed the google.com address to safatw.com (safari-alltheweb), then added www.safatw.com to my /etc/hosts file.



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: gsdali on Oct 18, '03 07:12:46AM
Anyone know how to recast this hint to that -trackback or -mt-tb.cgi could be appended to the search term as suggested by this letter to The Register. I've had a poke around but can't think how to do it.

---
--
Ed Lynch-Bell
dali@zerointegrity.co.uk

[ Reply to This | # ]

Change Safari's default search engine - revisited
Authored by: kitzkikz on Nov 08, '03 03:18:21PM
Instead of hacking Safari, get the same functionality using Sogudi. It allows you to type a shortcut followed by the search terms into the address bar and Safari then loads the results.

[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: sjk on Feb 20, '04 05:05:12PM

Sogudi's great! No search history like in the Google Search field, but that's never been too important for me. I removed GS from the Address Bar anyway soon after installing Sogudi to give longer URLs more room to display.



[ Reply to This | # ]
String for searching dictionary.com
Authored by: sonic on Jan 01, '04 08:44:05PM

if you want to have the field search dictionary.com, put in this string:

http://%@012:@dictionary.reference.com/%@?q=%@



[ Reply to This | # ]
"www" and "search" are also modifiable
Authored by: fy on Jan 04, '04 12:38:14PM
Although it may have been already pointed out somewhere,
 "www" and "search" are also defined in the same file,
 just after "RecentSearchStrings", and can be modified
 to enable longer option and/or engine with strange URL.

[ Reply to This | # ]
Change Safari's default search engine - GOOGLE.CO.UK
Authored by: arumdevil on Apr 11, '06 04:13:45AM
to use google.co.uk as the search engine use the following:
http://%@@google.co.uk/search?hl=en&q=%@&meta=
note that this will still search the whole web and not only UK sites. a

[ Reply to This | # ]
Change Safari's default search engine - GOOGLE.CO.UK
Authored by: arumdevil on Apr 11, '06 04:28:43AM
my mistake, doesn't work, sorry. try this instead

[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: volsmd99 on May 02, '06 10:22:33AM

Does anyone know how to change the engine to Dogpile. I can't seem to get it to work.



[ Reply to This | # ]
AcidSearch alternative
Authored by: sjk on May 08, '06 06:23:10PM
You (and others) might rather install/configure AcidSearch instead of directly hacking Safari.

[ Reply to This | # ]
AcidSearch alternative
Authored by: volsmd99 on May 10, '06 10:25:27AM

I've already tried Acidsearch. Unfortunately, it caused Safari to randomly crash even after a reinstall of Tiger. I was hoping a small modification of Safari would produce better results.



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: Guntis on Oct 21, '06 03:11:04PM
Or, you can change the default search engine with the 3rd party utility called Saft (http://haoli.dnsalias.com) It costs $6.00, and it offers many improvements, like Aqua toolbar, many search engines (and you can add your own), Adding and sorting Bookmarks in the Bookmark menu, etc. Worth every penny.

---
"In a world without fences and walls, who needs Gates and Windows?"

[ Reply to This | # ]

Change Safari's default search engine - revisited
Authored by: Herve5 on Feb 24, '07 08:04:37AM
There is also the free SafariKeyWords http://safarikeywords.sourceforge.net/ but I didn't try it in-depth yet. Only PPC code, but looks extremely easy to set up...
Herv

[ Reply to This | # ]
All you need is the free AcidSearch
Authored by: Herve5 on Mar 01, '07 04:02:42AM
http://www.pozytron.com/acidsearch
after having tried man things, and given a wrong advice to an obsolete app at the bottom of this thread... AcidSearch just rocks :-)

Herv

[ Reply to This | # ]
No URLs in the code
Authored by: mdg on Jun 09, '07 09:37:56AM

When I vi /Applications/Safari.app/Contents/MacOS/Safari I see only about a dozen lines of code, consisting primarily of the characters ^@ with no URLs at all. Has the Safari code changed so that this hint no longer works or am I doing something wrong?



[ Reply to This | # ]
No URLs in the code
Authored by: PiFan7 on Jun 27, '07 12:01:20PM
This still works for both Safari 2 and Safari 3 beta. You have to do a search to find the string to replace it. I found this manual very helpful to figure out how to use vi:
http://www.cs.fsu.edu/general/vimanual.html

It gave me all of the info I needed, including searching, deleting, inserting, saving, and exiting.

Also, notice the string for yahoo needs correcting from what was presented in the original post. This one works for me:
http://%@.%@.yahoo.com/bin/search?p=%@&a=00000



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: nacredata on Jun 12, '07 08:03:32PM
tbreihol has the ticket for making this a completely general solution. Thanks!

Here's my hack to use goodsearch.com

Crack open the Safari binary
(/Applications/Safari.app/Contents/MacOS/Safari)

substitute the second string below for the first where you find it:

http://%@.google.net/%@?q=%@&ie=UTF-8&oe=UTF-8

http://%@.g.net/Search.aspx?ooo=%@&Keywords=%@

("ooo" has no meaning - any three characters not recognized by GoodSearch will
do)

add this to /etc/hosts
72.32.179.130 www.g.net


[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: shinyplasticbag on Nov 13, '07 05:51:27AM

Hi;

I've sort of formalized this a bit into what I think is pretty much the ultimate solution. It's pretty flexible -- I did it to add search keywords to the Google box (ie, "wiki Mac OS X" to view a Wikipedia article). Since this thread was my original inspiration, I thought I'd share. Take a look and let me know what you think.

Safari Keywords



[ Reply to This | # ]
Change Safari's default search engine - revisited
Authored by: Milkshake2 on Dec 20, '08 03:18:27PM
change default to google.nl

To add to all the above:

To change the default from www.google.com to www.google.nl, do the following:

Fire up Terminal and cd to
/Applications/Safari.app/Contents/MacOS

copy (cp) the file Safari to Safari.old (in case you make a mistake)

Edit the Safari file with vi or your favorite editor:
vi Safari

search for the string:
http://%@.google.com/%@?q=%@&ie=UTF-8&oe=UTF-8
And replace it with:
http://%@.google.nl/%@?&q=%@&btnG=Zoeken&meta=

Make sure the string is exact (it has the same length as the original string).

Save the file and quit the editor.

Fire up Safari


In Dutch:
Maak google.nl de default zoekmachine in Safari.



[ Reply to This | # ]

Easy: this is one of the many features of Glims
Authored by: JohnDCCIU on Feb 28, '10 08:38:21PM
Give Glims a try. Giving the user a nice GUI to change the default search engine (much like Firefox's) is just one of the many fantastic features of this free and comprehensive Safari enhancement.

[ Reply to This | # ]