Forum Archive

Issues opening textastic to view source

miwagner1

Am I missing something here? It is not opening the textastic app.

# coding: utf-8

import appex
import webbrowser
from urlparse import urlsplit

def main():
    if not appex.is_running_extension():
        print 'This script is intended to be run from the sharing extension.'
        return
    url = appex.get_url()
    if not url:
        print 'No input URL found.'
        return
    url = urlsplit(url)
    url = 'textastic://' + url.netloc + url.path + url.query + url.fragment
    print url
    webbrowser.open(url)

if __name__ == '__main__':
    main()
marcus67

@miwagner1 Could you post the typical output of the print statement, please?

JonB

share app extensions cannot launch other apps. Only Today Widgets. Its an Apple thing.

miwagner1

Marcus67 the typical output looks like

textastic://forum.omz-software.com/topic/2616/can-pythonista-push-itself-into-the-foreground

Well dam if an extension can't open an app, I'm going to have to get fancy for viewing source code.

miwagner1

Ok so workflow can open other apps from the app extension. The user just had to confirm it. So how would I do this from the pythonista extension?

JonB

I think workflow has a today extension? so maybe that's it?
Alternatively, you could post a notification. If you set pythonista notifications to alerts instead of banners, then younwould effectively get prompted to open the app.

JonB

scratch that... this does work

import appex
from objc_util import *
app=UIApplication.sharedApplication()
url=nsurl('pythonista://')
app.openURL_(url)
appex.finish() #optional to close appex in containing spp, otherwise it will be there when you return.
omz

@JonB Nice one! Didn't know that was possible.

JonB

based on this... except that when I walked up the responder chain it turned out to be the sharedApplication()

miwagner1

This is fantastic. There are so many possibilities I can do now with pythonista and editorial with webpages. Right in the safari app.

Webmaster4o

@omz In the thread to which @JonB linked, people reported success with putting this method through apple review. You should implement this as the default behavior for webbrowser.open when called from appex.

miwagner1

No wonder he was surprised it worked. Apples docs say the UIApplication is Not available in app extensions.

It's possible this will break in later iOS versions.