public
Last active

open url in safari from pythonista

  • Download Gist
OpenURL.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# a bit of a hack
# by Cormac Relf - cormacrelf.com - @cormacrelf
 
# Opens the url on the clipboard in Safari
# by opening Google Chrome with an x-callback-url
# that takes you to the same url in Safari.
 
# I guess you could just open it in googlechrome://
 
import webbrowser
import clipboard
import console
import urllib
import re
 
url = clipboard.get()
 
url = urllib.quote_plus(url)
 
callback = "googlechrome-x-callback://x-callback-url/open/?url=YOURL&x-source=Safari&x-success=YOURL"
 
callback = re.sub("YOURL", url, callback)
 
#console.clear()
#print(callback)
 
webbrowser.open(callback)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.