I have a script here that runs google image search on whatever URL is in clipboard.
It works perfectly **in Pythonista. **
But I want it to work from within Safari (That means from Safari->'Run Pythonista Script'->'My script.py'.
It will not open the tab if run in this way from Safari. Is there a way to make this work?
My code is simply:
```
import clipboard
import webbrowser
def is_url(image_url):
''' Accepts a url [string]. Returns True if url is valid. '''
try:
return image_url.startswith('http://')
except:
print 'Invalid URL.'
return False
def create_url(image_url):
''' Accepts an image_url [string]. Returns search by image URL. '''
search_url = 'https://www.google.co.uk/searchbyimage?&image_url='
try:
search_url += image_url
except:
print 'Could not create URL from clipboard.'
return search_url
def main():
image_url = clipboard.get()
if is_url(image_url):
search_url = create_url(image_url)
webbrowser.open('safari-' + search_url)
print 'Done.'
if name == 'main':
main()```