omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    4
    5
    4450
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • lunkan49
      lunkan49 last edited by

      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.py

      import sys
      import pprint
      import console

      console.clear()

      pprint.pprint(sys.argv[1:])
      </pre>

      You get the idea! Lets go nuts! :)

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        Great idea, thanks!

        1 Reply Last reply Reply Quote 0
        • PKHG222
          PKHG222 last edited by

          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") !!

          1 Reply Last reply Reply Quote 0
          • lunkan49
            lunkan49 last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • C0deH4cker
              C0deH4cker last edited by

              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!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors