Skip to content

Instantly share code, notes, and snippets.

@m-zheng
Created March 12, 2023 13:41
Show Gist options
  • Save m-zheng/1e71a03cfa62597035b62bd568572589 to your computer and use it in GitHub Desktop.
Save m-zheng/1e71a03cfa62597035b62bd568572589 to your computer and use it in GitHub Desktop.
How to add a new search engine to Safari

How to add a new search engine to Safari

Background

Apple does not allow users to add a new search engine to Safari. If users want to use Safari or Spotlight to search from web, they have no choice but to use whatever search engine provided by Apple.

Aim

To use any search engine as the default search engine on macOS, iOS or ipadOS globally. Startpage is used here as an example. This means apple device owners can:

  1. Use Startpage as the default search engine in Safari address bar.
  2. Use Startpage as the default search engine in Spotlight.
  3. Override Search with Google in macOS Context Menu.
  4. Override Search Web in iOS and iPadOS Context Menu.

Solution

  1. Apple does not allow users to add a new search engine in Safari. But the search url can be redirected to any search engine.
  2. Install a Safari extension called Redirect Web for Safari.
  3. If you use a different browser on macOS, such as Firefox or Chrome, an addon called Redirector is required.

Redirect Web for Safari

It is a free Safari extension. It is not required to pay for premium features as the free functionalities are good enough to get the job done. Having said that, purchasing premium features is a good way to support its developer.

  1. Set Google as the default search engine in Safari.
  2. Save code below to a file with an extension of redirectweb, e.g. dummmy.redirectweb. Then click the Redirect Web for Safari icon in Safari Toolbar and import the rule.
  3. In Safari settings, allow Redirect Web for Safari to read all websites you visit.
{
  "appVersion" : "4.5.0",
  "bundleID" : "io.github.mshibanami.RedirectWebForSafari",
  "createdAt" : "2023-03-07T00:40:04.501Z",
  "kind" : "RedirectList",
  "redirects" : [
    {
      "appOpenerPostActions" : [

      ],
      "captureGroupProcesses" : [

      ],
      "comments" : "",
      "destinationURLPattern" : "https:\/\/www.startpage.com\/do\/dsearch?query=$2",
      "exampleURLs" : [
        "https:\/\/www.google.co.uk\/search?q=what+is+my+ip+address&ie=UTF-8&oe=UTF-8&hl=en-gb&client=safari",
        "https:\/\/www.google.com\/search?client=safari&rls=en&q=what+is+my+ip+address&ie=UTF-8&oe=UTF-8&safe=active",
        "https:\/\/www.google.co.uk\/search?q=what+is+my+ip+address&ie=UTF-8&oe=UTF-8&hl=en-gb&client=safari&safe=active"
      ],
      "excludeURLPatterns" : [

      ],
      "isEnabled" : true,
      "kind" : "Redirect",
      "sourceURLPattern" : {
        "type" : "regularExpression",
        "value" : "^(?:https?:\\\/\\\/)(?:www.)google\\.(?:com|au|de|co.uk)\\\/search\\?(.+&)?q=([^&]+)(&.*)?"
      },
      "title" : "Redirect google search to startpage"
    }
  ]
}

Redirector

This step is required only if the default browser on macOS is not Safari. It is worth mentioning that Search with Google launches Safari regardless of the default browser setting.

  1. Install Redirector addon in your browser.
  2. Save code below to a json file and import it to Redirector.
{
    "createdBy": "Redirector v3.5.3",
    "createdAt": "2023-03-07T18:02:29.643Z",
    "redirects": [
        {
            "description": "Redirect spotlight google search to startpage",
            "exampleUrl": "https://www.google.com/search?client=safari&rls=en&q=what+is+my+ip+address&ie=UTF-8&oe=UTF-8&safe=active",
            "exampleResult": "https://www.startpage.com/do/dsearch?query=what+is+my+ip+address",
            "error": null,
            "includePattern": "^(?:https?:\\/\\/)(?:www.)google\\.(?:com|au|de|co.uk)\\/search\\?(.+&)?q=([^&]+)(&.*)?",
            "excludePattern": "",
            "patternDesc": "Any word inside the q parameter goes to startpage search engine.",
            "redirectUrl": "https://www.startpage.com/do/dsearch?query=$2",
            "patternType": "R",
            "processMatches": "noProcessing",
            "disabled": false,
            "grouped": false,
            "appliesTo": [
                "main_frame"
            ]
        }
    ]
}

Acknowledgement

  1. A huge thank you for Redirect Web for Safari developer's help to create the redirect rule.
  2. A huge thank you for the open source project Redirector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment