Skip to content

Instantly share code, notes, and snippets.

@Juan-Embid
Created March 2, 2022 11:17
Show Gist options
  • Select an option

  • Save Juan-Embid/7e80013f7f639db7e8c5f955f1edb798 to your computer and use it in GitHub Desktop.

Select an option

Save Juan-Embid/7e80013f7f639db7e8c5f955f1edb798 to your computer and use it in GitHub Desktop.
Script to search, find and open your default browser in linux
import subprocess
default_input = ['xdg-mime', 'query', 'default', 'x-scheme-handler/http']
default_executable = ['grep', 'Exec', '-w', '-m1']
final_search = ['github.com/Juan-Embid'] #the page you decide to open
web_page_file = subprocess.run(default_input, stdout=subprocess.PIPE).stdout.decode('utf-8')
web_page_file = web_page_file.split("\n")
web_page_file_path = "/usr/share/applications/" + web_page_file[0]
default_executable.insert(2, web_page_file_path)
web_page_command = subprocess.run(default_executable, stdout=subprocess.PIPE).stdout.decode('utf-8')
web_page = web_page_command.split("=")
final_search.insert(0, web_page[1].strip("\n%U "))
subprocess.run(final_search, stdout=subprocess.PIPE).stdout.decode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment