Advertisement
Python253

set_ecosia_default_search_engine

Mar 3rd, 2024
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Filename: set_ecosia_default_search_engine.py
  3. # Author: Jeoi Reqi
  4.  
  5. """
  6. Set Default Search Engine in Google Chrome
  7.  
  8. This Python script allows users to easily set their default search engine in Google Chrome to the Ecosia Search Engine.
  9.  
  10. Requirements:
  11. - Python 3
  12.  
  13. Usage:
  14. 1: Ensure Python 3 is installed on your system.
  15. 2: Copy and paste the script into a Python file.
  16. 3: Customize the search engine settings within the script if desired.
  17. 4: Run the script.
  18.  
  19. The script will update your Chrome preferences, setting the Ecosia Search Engine as the default.
  20.  
  21. Note: Make sure to run the script with the appropriate permissions, and modify the Chrome preferences file path if your Chrome installation directory differs.
  22. """
  23.  
  24. import os
  25. import json
  26.  
  27. # Path to the Chrome preferences file
  28. PREFS_FILE = os.path.join(os.getenv('LOCALAPPDATA'), 'Google', 'Chrome', 'User Data', 'Default', 'Preferences')
  29.  
  30. # Search engine settings to add to the Chrome preferences for Ecosia
  31. ECOSIA_SETTINGS = {
  32.     "default_search_provider": {
  33.         "enabled": True,
  34.         "encodings": {"query": "UTF-8", "search_url": "UTF-8"},
  35.         "favicon_url": "https://www.ecosia.org/favicon.png",
  36.         "id": "6",
  37.         "image_url": "https://www.ecosia.org/assets/images/png/logo_1024.png",
  38.         "image_url_post_params": "",
  39.         "instant_url": "",
  40.         "keyword": "ecosia.org",
  41.         "name": "Ecosia",
  42.         "search_url": "https://www.ecosia.org/search?q={searchTerms}",
  43.         "suggest_url": ""
  44.     }
  45. }
  46.  
  47. # Check if the Chrome preferences file exists
  48. if not os.path.isfile(PREFS_FILE):
  49.     print("Error: Chrome preferences file not found")
  50.     exit(1)
  51.  
  52. # Read current preferences from the file
  53. with open(PREFS_FILE, 'r', encoding='utf-8') as file:
  54.     preferences = json.load(file)
  55.  
  56. # Update preferences with Ecosia as a search engine
  57. preferences.update(ECOSIA_SETTINGS)
  58.  
  59. # Write the updated preferences back to the file
  60. with open(PREFS_FILE, 'w', encoding='utf-8') as file:
  61.     json.dump(preferences, file, indent=2)
  62.  
  63. print("Success: Ecosia has been added as a search engine in Google Chrome")
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement