Forum Archive

Setting to define a script to directly launch if sharing extension

cvp

Would it be possible to have a setting where we could define a particular script to run when Pythonista 3 is chosen in the sharing extension without passing by the standard Pythonista window?

dgelessus

This is already possible - the pythonista_startup script runs in the extension too. So at the bottom of your pythonista_startup you could add something like:

if appex.is_running_extension():
    # run appex script
cvp

I was sure I would not be clear enough with my very poor English.
I know this script and appex etc...
I would write an "appex mode" script which would directly run when you click the Pythonista 3 icon in the share sheet, like if my script was The app it-self.

omz

@dgelessus There's no guarantee that the app extension is launched in a new process, so the startup script may not always run. I guess you could swizzle something there to make your script run every time the extension is shown, but, to answer the original question, there's no easy/supported way to do this.

cvp

Thanks to both of you

JonB

Are you only allowed to expose one share sheet button per app?
I think the question is sort of whether you could have the generic pythonista share button, as well as a PythonistaUserDefined default, which is set to run a specific script, set in settings.

cvp

Thanks to exactly clarify my question

omz

Each app extension only has one button in the share sheet, and its icon/title is static, i.e. cannot be changed programmatically. Yes, it would theoretically be possible to include multiple app extensions in one app, but those would actually be separate binaries, and I don't think that would be worth it.

cvp

Thanks for your answer.
Could the other actions of the Pythonista share sheet like edit, done, scratch pad, all scripts, console be hidden to only show user icon(s) for an "end user"?

cvp

Finally, I'm really sure I wasn't clear.
I don't ask a second icon but that if we click the Pythonista icon an user script would be directly called without passing by the standard window
not this