-
lunkan49
Hello!
I made a simple script to demonstrate how to create a bookmarklet in safari that calls a python script in pythonista and passes the current safari URL as a parameter to that script.
It's not rocket science, you can figure out the details yourself.This is the JavaScript code you should use to create the bookmark. DoStuff is the name of the python script that is run in my example:
<pre>
javascript:(function(){if(document.location.href.indexOf('http')===0)document.location.href='pythonista://DoStuff?action=run&argv='+document.location.href;})();
</pre>Now for the simple script. It just prints out the params passed to it except the name of the script itself:
<pre>
#DoStuff.pyimport sys
import pprint
import consoleconsole.clear()
pprint.pprint(sys.argv[1:])
</pre>You get the idea! Lets go nuts! :)
-
lunkan49
Lets see if you can see the JavaScript line better if I don't put it in code-blocks!
javascript:(function(){if(document.location.href.indexOf('http')===0)document.location.href='pythonista://DoStuff?action=run&argv='+document.location.href;})();
I just made a bookmarklet that parses all image URLs from a web page and copies them to the clipboard. The combo of input through Safari and JavaScript and output to clipboard is quite powerful. You don't have to stop there since you can forward the result to other apps that have URL-schemes for input.