76

Python library to create Siri Shortcuts

 5 years ago
source link: https://www.tuicool.com/articles/hit/nq6fU3Z
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WIP: python-shortcuts

:green_apple: + :snake: = :heart:

python-shortcutsis a library to create Siri Shortcuts on your laptop with your favourite text editor. It uses toml to represent shortcuts.

The library is in a very early development state (PR welcome!), so it does not support all actions from Shortcuts app.

Why

I wanted to convert my shortcut to a file in human-readable format. :)

From the code below this library can create a working shortcut:

[[action]]
type = "ask"
question = "What is your name?"

[[action]]
type = "set_variable"
name = "name"

[[action]]
type = "show_result"
text = "Hello, {{name}}!"

How to use

Requirements

This library requires plutil tool, which should be installed on MacOS by default. On Linux, you should be able to use plistutil instead.

Installation

pip install python-shortcuts

Usage

shortcut → toml

If you need to convert existing shortcut to a toml file, at first you need to export it. Go into Shortcuts app, open the shortcut and share it. Choose "Share as file" and use this file with this library.

Convert toml file with shortcut description to a real shortcut file. After you need to open the file with iOS Shortcuts app.

shortcuts what_is_your_name.shortcut what_is_your_name.toml

toml → shortcut

Also, you can convert shortcut file to a toml :

shortcuts examples/what_is_your_name.toml what_is_your_name.shortcut

More examples of toml files you can find here . And read the tutorial ! :)

Development

Tests

Run tests:

tox

TODO

  • ☐ Conditionals with auto-group_id: if-else, menu
  • ☐ Nested fields: dict/array/etc
  • ☐ Support variables in every field which support them in Shortcuts app
  • ☐ Workflow types: widget, etc.
  • ☐ Describe all actions
  • ☐ Support magic variables
  • ☐ Support all current actions from Shortcuts app

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK