Skip to content

Instantly share code, notes, and snippets.

@stedman
Last active March 9, 2021 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stedman/5b596450524cbf1a1f941de888798ef6 to your computer and use it in GitHub Desktop.
Save stedman/5b596450524cbf1a1f941de888798ef6 to your computer and use it in GitHub Desktop.
Load local development URL in multiple browsers simultaneously.
#!/usr/bin/python
##
## Load local development URL in multiple browsers simultaneously.
##
import subprocess
browsers = {
'brave': {
'title': 'Brave',
'location': '/Applications/Brave\ Browser.app'
},
'chrome': {
'title': 'Chrome',
'location': '/Applications/Google\ Chrome.app'
},
'edge': {
'title': 'Edge',
'location': '/Applications/Microsoft\ Edge.app'
},
'firefox': {
'title': 'Firefox',
'location': '/Applications/Firefox.app'
},
'firefox_dev': {
'title': 'Firefox Developer',
'location': '/Applications/FirefoxDeveloperEdition.app'
},
'safari': {
'title': 'Safari',
'location': '/Applications/Safari.app'
},
'ios_sim': {
'title': 'IOS Simulator',
'location': '/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app'
}
}
url = 'http://localhost'
url_input = raw_input('If you wish to view an URL other than http://localhost, then enter that now: ')
if url_input != '':
url = url_input
print ' We will use {url}\n'.format(url=url)
# Store preferred browsers.
preferred_browsers = []
# Ask for preferred browsers.
for key in browsers:
browser = browsers[key]
open_browser = raw_input('Load {brow}? (Y|n)'.format(brow=browser['title'])).lower()
if open_browser != 'n':
preferred_browsers.append(key)
print ' {brow} will be loaded...'.format(brow=browser['title'])
# Open the preferred browsers.
for browser_key in preferred_browsers:
if browser_key == 'ios_sim':
cmd = 'open -a {app};sleep 4;xcrun simctl openurl booted {url}'.format(app=browsers[browser_key]['location'], url=url)
else:
cmd = 'open -a {app} {url}'.format(app=browsers[browser_key]['location'], url=url)
print '\nNow opening {brow}...'.format(brow=browsers[browser_key]['title'])
subprocess.call(cmd, shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment