Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Safari Bookmarklet to run python script
-
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! :)
-
Great idea, thanks!
-
FF show this line:
javascript:(function(){if(document.location.href.indexOf('http')===0)document.location.href='pythonista://DoStuff?act
very strange: so OMZ, is there a nice code beautifier for your forum application? (see my wiki, using "geshi") !!
-
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.
-
Sorry for the cross post, but I thought that this would fit here too.
I have just updated the multifile gist example with my own:
https://gist.github.com/5f3f2035d8aa46de42ad
Save that as "gist" and add the following bookmarklet called "Get Gist" to safari:
javascript:(function()%7Bif(document.location.href.indexOf('http')===0)document.location.href='pythonista://gist?action=run&argv='+document.location.href;%7D)();
Now, whenever you are looking at a gist script that you want to try in Pythonista, just click the bookmarklet and it will instantly download and display the code for you. Enjoy!