Create pythonista:// webclips directly from Pythonista
I hope this helps everyone out :)
My code dynamically generates a .mobileconfig file which is normally used to provision iOS devices. One of the things it can provision is the <u>installation of webclips</u> to custom URLs (with custom icons).
... Unfortunately the built-in web browser in Pythonista doesn't seem to be able to install them ... but with a little switchery trickery, we can use both Mobile Safari and Pythonista together!
When you run the code, it starts a web server in Pythonista - and copies the URL for the generated .mobileconfig file to the clipboard. When you switch to Safari and attempt to load the URL, the socket connects - but it's waiting for communication from the web server in Pythonista (which is paused, since it's in the background).
<b>As soon as you switch back to Pythonista,</b> this un-pauses the web server fast enough to cause Safari to finish loading the .mobileconfig file while it's swapping to the background, which then triggers the installation screen!
Once it's served up a single mobileconfig file, the script stops.
If you want to remove the web clip you create, you can 'x' it out - but be aware it leaves the installation profile behind (Settings -> General -> Profiles), which you should probably also remove.
I made the code pretty clear where you can set the icon label name, script name, arg string, and payload name (the name that shows in the profile list). Both the profile and web clip payloads are generated with random UUIDs, so you can have as many installed as you like - installing one won't replace / modify another.
If you want a different icon for your webclips, the data is just a base64 encoded raw .png file. Feel free to swap it out.
Also, if someone would like to put a pretty interactive interface on this (before I do), by all means please do :)
Right now, though, I gotta get some ZZZzzs before Turkey Day.
<b>Quick Edit:</b> While I remember it - I'm doing args as a blank string currently. If you do intend to pass a complex argstring, you'll probably need to URL encode it. Just an FYI.
One other side comment - this was tested with an iPhone 4S running iOS 6.
If people end up finding out their devices don't work with this switchery trickery (due to speed or whatever), it's also possible to email / Dropbox upload / put the generated .mobileconfig file in some other location that it would make it either easier to load in Safari or a clickable attachment.
Just a thought for the future.
Ha, sneaky! :)
I can think of a few ways I could improve this flow in a future Pythonista update (e.g. make it possible to open http URLs in Safari instead of the built-in browser and maybe continue running a script for 30 seconds or so after going to the background).
I really like this utility. I've made a utility to convert a clipboard image to a 57x57 rgb base64 image on the clipboard. https://gist.github.com/4132799. It makes it easier to customize the image.
@omz - Just the ability to pass use_safari=True as an optional arg to webbrowser.open or as its own method like .mobile_open(...) would be fantastic.
Plus the extended background running that is :)
Glad this script is proving useful to some.
Mind you, it can create webclips to anything - not just Pythonista scripts.
I sometimes need to make webclips when not connected to the internet, and this script is perfect for that. Nifty tool.
@Uberi - Quite welcome :)