[IOS] Use a shared sheet with Pythonista3.

Introduction

A note on how to launch a Pythonista 3 script from the iOS Share menu.

Shared menu

iOS has a sharing menu that allows you to pass data to other apps, and you will see the following icons in various situations. share In the menu that appears when you tap this, in addition to the standard ** AirDrop **, ** message **, ** mail **, there are installed apps that support ** shared sheet **. The lineup and ** actions ** corresponding to the operation at that time are also displayed. Run Pythonista Script When ** Pythonista3 ** is installed, a menu called ** Run Pythonista Script ** will be added to the ** Actions column ** of the Share menu.

When you tap this menu, the icons of the scripts registered in advance will be lined up.

share This is a script preset in **. / Examples / Extension **. Since you can register your own script here, you can also use it to receive data from other apps, process it, and then save it.

The following sample rotates the received image 90 degrees clockwise and displays it on the console.

test.py



import appex
import console

def main():
  if not appex.is_running_extension():
    console.hud_alert('Please execute from the shared sheet.','error',2)
    return

  image = appex.get_image()
  if not image:
    console.hud_alert('Image not found.','error',2)
    return
  
  #Rotate the image and display it on the console.
  image = image.rotate(270, expand=True)
  image.show()
  
if __name__ == '__main__':
  main()

I have made it so that it can only be executed from the share menu, so next I will make it possible to execute it from the share menu.

Share Extension Shortcuts

You can register ** Share Extension Shortcuts ** from the ** Pythonista ** settings screen, but you can also register from the share menu of the photo app, so try it from the photo app.

  1. Open the share menu with the image open.
  2. Tap ** Run Pythonista Script **.
  3. Tap ** Edit ** and tap the "⊕" icon that appears.
  4. A file selection dialog will be displayed. Select the script you want to register. In the video, select ʻExamples / Extension / test.py`.
  5. You can make various settings, but this time we only need to register, so tap ** Add **.
  6. If the icon of the script you just registered is added, the registration is successful.
  7. Tap the icon to run the script. A18DCF13-7504-4514-8E2E-DB7373B23A45.gif

The original video link of the above GIF.

Recommended Posts

[IOS] Use a shared sheet with Pythonista3.
Use shared memory with shared libraries
[IOS] Disassemble GIF animation with Pythonista3.
Use a custom kernel with WSL2
Add images to iOS photos with Pythonista
Decrypt a string encrypted on iOS with Python
A story about making Hanon-like sheet music with Python
Upload to a shared drive with Google Drive API V3
Display Matsuya coupon (QR code) with Pythonista for iOS
Use KNP as a Universal Dependency parser with spaCy
Use mecab-ipadic-neologd with igo-python
Use RTX 3090 with PyTorch
Use pipdeptree with virtualenv
[Python] Use JSON with Python
Use indicator with pd.merge
A4 size with python-pptx
Use mecab with Python3
Use tensorboard with Chainer
Use pip with MSYS2
Use a Property Decorator?
Use Python 3.8 with Anaconda
Use pyright with Spacemacs
Use python with docker
Use TypeScript with django-compressor
Use LESS with Django
Use MySQL with Django
Decorate with a decorator
Use Enums with SQLAlchemy
Use tensorboard with NNabla
Use GPS with Edison
Use nim with Jupyter
[IOS] GIF animation with Pythonista3. I was addicted to it.
Use a macro that runs when saving python with vscode
I want to use a virtual environment with jupyter notebook!
Make a BLE thermometer and get the temperature with Pythonista3