Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Filename: set_default_search_engine_in_chrome_full_menu.py
- # Author: Jeoi Reqi
- """
- Set Default Search Engine in Google Chrome
- This Python script allows users to easily set their default search engine in Google Chrome from a menu of popular options.
- The script provides a user-friendly interface, presenting a menu with a selection of search engines such as Google, DuckDuckGo,
- Bing, Yandex, Baidu, WolframAlpha, and Ecosia.
- Requirements:
- - Python 3
- Usage:
- 1: Ensure Python 3 is installed on your system.
- 2: Copy and paste the script into a Python file.
- 3: Customize the search engine settings within the script if desired.
- 4: Run the script, and a menu will appear.
- 5: Enter the ID of the preferred search engine from the menu.
- The script will update your Chrome preferences, setting the chosen search engine as the default.
- Note: Make sure to run the script with the appropriate permissions, and modify the Chrome preferences file path if your Chrome installation directory differs.
- """
- import os
- import json
- def set_search_engine(search_engine_settings, engine_name):
- # Path to the Chrome preferences file
- PREFS_FILE = os.path.join(os.getenv('LOCALAPPDATA'), 'Google', 'Chrome', 'User Data', 'Default', 'Preferences')
- # Check if the Chrome preferences file exists
- if not os.path.isfile(PREFS_FILE):
- print("Error: Chrome preferences file not found")
- exit(1)
- # Read current preferences from the file
- with open(PREFS_FILE, 'r', encoding='utf-8') as file:
- preferences = json.load(file)
- # Update preferences with the chosen search engine
- preferences.update(search_engine_settings)
- # Write the updated preferences back to the file
- with open(PREFS_FILE, 'w', encoding='utf-8') as file:
- json.dump(preferences, file, indent=2)
- print(f"Success: {engine_name} has been set as your default search engine in Google Chrome")
- def menu():
- print("::[Select a search engine to set as default]::\n")
- print("-------------------------------------------")
- print("0: Google -------- Global #1 Search Engine\n")
- print("1: DuckDuckGo ---- Engine Owned By Google\n")
- print("2: Bing ---------- Microsoft's Search Engine\n")
- print("3: Yandex -------- Russia's #1 Search Engine\n")
- print("4: Baidu --------- China's #1 Search Engine\n")
- print("5: WolframAlpha -- Computational Search Engine\n")
- print("6: Ecosia -------- Plants Trees For Searches 🌳\n")
- choice = input("\nEnter the ID of the search engine you want to set as default: ")
- if choice == "0":
- set_search_engine(GOOGLE_SEARCH_ENGINE, "Google")
- elif choice == "1":
- set_search_engine(DUCKDUCKGO_SEARCH_ENGINE, "DuckDuckGo")
- elif choice == "2":
- set_search_engine(BING_SEARCH_ENGINE, "Bing")
- elif choice == "3":
- set_search_engine(YANDEX_SEARCH_ENGINE, "Yandex")
- elif choice == "4":
- set_search_engine(BAIDU_SEARCH_ENGINE, "Baidu")
- elif choice == "5":
- set_search_engine(WOLFRAMALPHA_SEARCH_ENGINE, "WolframAlpha")
- elif choice == "6":
- set_search_engine(ECOSIA_SETTINGS, "Ecosia")
- else:
- print("Invalid choice. Please enter a valid search engine ID.")
- # Search engine settings
- GOOGLE_SEARCH_ENGINE = {
- "default_search_provider": {
- "enabled": True,
- "encodings": {"query": "UTF-8", "search_url": "UTF-8"},
- "favicon_url": "https://www.google.com/favicon.ico",
- "id": "0",
- "image_url": "",
- "image_url_post_params": "",
- "instant_url": "",
- "keyword": "google.com",
- "name": "Google",
- "search_url": "https://www.google.com/search?q={searchTerms}",
- "suggest_url": ""
- }
- }
- DUCKDUCKGO_SEARCH_ENGINE = {
- "default_search_provider": {
- "enabled": True,
- "encodings": {"query": "UTF-8", "search_url": "UTF-8"},
- "favicon_url": "https://duckduckgo.com/favicon.ico",
- "id": "1",
- "image_url": "https://duckduckgo.com/assets/logo.icon.svg",
- "image_url_post_params": "",
- "instant_url": "",
- "keyword": "duckduckgo.com",
- "name": "DuckDuckGo",
- "search_url": "https://duckduckgo.com/?q={searchTerms}",
- "suggest_url": ""
- }
- }
- BING_SEARCH_ENGINE = {
- "default_search_provider": {
- "enabled": True,
- "encodings": {"query": "UTF-8", "search_url": "UTF-8"},
- "favicon_url": "https://www.bing.com/favicon.ico",
- "id": "2",
- "image_url": "https://www.bing.com/sa/simg/favicon-2x.ico",
- "image_url_post_params": "",
- "instant_url": "",
- "keyword": "bing.com",
- "name": "Bing",
- "search_url": "https://www.bing.com/search?q={searchTerms}",
- "suggest_url": ""
- }
- }
- YANDEX_SEARCH_ENGINE = {
- "default_search_provider": {
- "enabled": True,
- "encodings": {"query": "UTF-8", "search_url": "UTF-8"},
- "favicon_url": "https://yandex.com/favicon.ico",
- "id": "3",
- "image_url": "https://yandex.com/images/logo-share.png",
- "image_url_post_params": "",
- "instant_url": "",
- "keyword": "yandex.com",
- "name": "Yandex",
- "search_url": "https://yandex.com/search/?text={searchTerms}",
- "suggest_url": ""
- }
- }
- BAIDU_SEARCH_ENGINE = {
- "default_search_provider": {
- "enabled": True,
- "encodings": {"query": "UTF-8", "search_url": "UTF-8"},
- "favicon_url": "https://www.baidu.com/favicon.ico",
- "id": "4",
- "image_url": "https://www.baidu.com/img/baidu_jgylogo3.gif",
- "image_url_post_params": "",
- "instant_url": "",
- "keyword": "baidu.com",
- "name": "Baidu",
- "search_url": "https://www.baidu.com/s?wd={searchTerms}",
- "suggest_url": ""
- }
- }
- WOLFRAMALPHA_SEARCH_ENGINE = {
- "default_search_provider": {
- "enabled": True,
- "encodings": {"query": "UTF-8", "search_url": "UTF-8"},
- "favicon_url": "https://www.wolframalpha.com/favicon.ico",
- "id": "5",
- "image_url": "https://www.wolframalpha.com/images/wa-share.png",
- "image_url_post_params": "",
- "instant_url": "",
- "keyword": "wolframalpha.com",
- "name": "WolframAlpha",
- "search_url": "https://www.wolframalpha.com/input/?i={searchTerms}",
- "suggest_url": ""
- }
- }
- ECOSIA_SETTINGS = {
- "default_search_provider": {
- "enabled": True,
- "encodings": {"query": "UTF-8", "search_url": "UTF-8"},
- "favicon_url": "https://www.ecosia.org/favicon.png",
- "id": "6",
- "image_url": "https://www.ecosia.org/assets/images/png/logo_1024.png",
- "image_url_post_params": "",
- "instant_url": "",
- "keyword": "ecosia.org",
- "name": "Ecosia",
- "search_url": "https://www.ecosia.org/search?q={searchTerms}",
- "suggest_url": ""
- }
- }
- if __name__ == "__main__":
- menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement