How do I perform ios “open with” from python code?
With Pythonista I can easily produce a file which will be saved in the Pythonista file system. If it has the appropriate file ending, in this case ".gpx", accessing that file will call up the ios dialog "open with" and a list of possible apps.
Is it possible, using the x-callback-url system, to open the ios app (in this case gaiagps://) with the above file directly from the python code, saving the extra step of clicking on the file?
This line is surely close:
@djl In this case, is this not sufficient ?
import ui import time import dialogs from objc_util import * def open_in_with_specified_activities(path_in,uiview): global handler_done,SUIViewController_service handler_done = False SUIViewController_service = None def handler(_cmd,obj1_ptr,_error): global handler_done,SUIViewController_service # obj1_ptr = None if no service selected if obj1_ptr: obj1 = ObjCInstance(obj1_ptr) SUIViewController_service = str(obj1) handler_done = True return vo = ObjCInstance(uiview) SUIViewController = ObjCClass('SUIViewController') root_vc = SUIViewController.viewControllerForView_(vo) main_view = root_vc.view() handler_block = ObjCBlock(handler, restype=None, argtypes=[c_void_p, c_void_p, c_void_p]) if type(path_in) is list or type(path_in) is tuple: path = path_in else: path = [path_in] url_array =  for elem in path: url_array.append(nsurl(elem)) UIActivityViewController = ObjCClass('UIActivityViewController').alloc().initWithActivityItems_applicationActivities_(url_array,None) UIActivityViewController.setCompletionWithItemsHandler_(handler_block) UIActivityViewController.popoverPresentationController().sourceView = main_view UIActivityViewController.popoverPresentationController().sourceRect = CGRect(CGPoint(10,10), CGSize(uiview.width,uiview.height)) root_vc.presentViewController_animated_completion_(UIActivityViewController, True, None) while not handler_done: time.sleep(1) if SUIViewController_service == None: SUIViewController_service = 'None' # for checking at return and use in alert return SUIViewController_service v = ui.View() v.frame = (0,0,600,400) v.background_color = 'white' v.present('sheet') service = open_in_with_specified_activities('sample.gpx', v) print(service) v.close()
@omz I always try to understand how the Shortcuts app is able to "open in" a particular application while sending it a file.
I've tried with UIDocumentInteractionController or UIActivityViewController but without success, it always needs an user action in the "open in" menu.
I just tried with Pythonista, passing it a .txt file and Shorcuts has launched Pythonista and has opened the txt file in a tab, thus Pythonista has imported the file.
Is there a Pythonista URL scheme to do that or is that proving that Shortcuts really shares the file?
The shortcut file contains
is.workflow.actions.openin _WFOpenInAskWhenRun _WFOpenInAppIdentifier_com.omz-software.Pythonista3¡&XWatchKit
Edit: for info, I've asked it by a email to the old address of Workflow support but without answer, of course because became Apple 😢
I also asked to gaiaGPS how Shortcuts could open a .gpx file into their app and they answer they don't have any integration with Shortcuts nor any URL Scheme for that...
But, if via share, you would need to choose which script to run...
@cvp I think your code above is fabulous, but I have not been able to strip it down to the bare minimum, without the GUI, and assuming 'all' as the default choice so that the code goes immediately to the "open with" dialog. Could you possibly provide a minimal version of your code? For me it would be perfect if it goes directly from a file name mentioned in the code to the "open with" popup.
@djl I'm really sorry, but obviously due to my English, I don't understand your request..
The last little script I posted is the minimum code to display the standard open_with of a file, without removing any service, but in this case, it is equivalent to the standard Pythonista console.open_in.
@cvp Thanks! It turns out that console.open_in is the only additional code I need for my project. As a beginner, I was unaware of this statement.
@djl My first post on this topic already gave it 😂