Last active
March 30, 2016 19:31
-
-
Save lsloan/206d8029cf12150b4ce06430b1cff672 to your computer and use it in GitHub Desktop.
Pythonista program to open a URL (given via iOS share sheet) in Safari. May require iOS 9. (Untested.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| # from: https://forum.omz-software.com/topic/2271/beta-suggestion-safariviewcontroller/9 | |
| from objc_util import * | |
| import appex | |
| SFSafariViewController = ObjCClass('SFSafariViewController') | |
| def open_in_safari_vc(url): | |
| vc = SFSafariViewController.alloc().initWithURL_entersReaderIfAvailable_(nsurl(url), True) | |
| app = UIApplication.sharedApplication() | |
| if app.keyWindow(): | |
| window = app.keyWindow() | |
| else: | |
| window = app.windows().firstObject() | |
| root_vc = window.rootViewController() | |
| while root_vc.presentedViewController(): | |
| root_vc = root_vc.presentedViewController() | |
| root_vc.presentViewController_animated_completion_(vc, True, None) | |
| vc.release() | |
| 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' | |
| return | |
| open_in_safari_vc(url) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment