项目作者: alexander-akhmetov

项目描述 :
Create Siri Shortcuts with Python
高级语言: Python
项目地址: git://github.com/alexander-akhmetov/python-shortcuts.git
创建时间: 2018-09-23T20:35:50Z
项目社区:https://github.com/alexander-akhmetov/python-shortcuts

开源协议:MIT License

下载


WIP: python-shortcuts

Build Status
PyPI

🍏 + 🐍 = ❤️

python-shortcuts is 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.

Supported Python version: >=3.6.

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:

  1. [[action]]
  2. type = "ask"
  3. question = "What is your name?"
  4. [[action]]
  5. type = "set_variable"
  6. name = "name"
  7. [[action]]
  8. type = "show_result"
  9. text = "Hello, {{name}}!"

Or the same with Python:

  1. from shortcuts import Shortcut, actions
  2. sc = Shortcut()
  3. sc.actions = [
  4. actions.AskAction(data={'question': 'What is your name?'}),
  5. actions.SetVariableAction(data={'name': 'name'}),
  6. actions.ShowResultAction(data={'text': 'Hello, {{name}}!'})
  7. ]

How to use

Installation

  1. pip install 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 shortcut file to toml:

  1. shortcuts what_is_your_name.shortcut what_is_your_name.toml

toml → shortcut

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

  1. 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! :)

URL → [toml|shortcut]

Also, you can download shortcut directly from iCloud.
If somebody shared shortcut link with you, just run:

  1. shortcuts https://www.icloud.com/shortcuts/... my_shortcut.toml # or my_shortcut.shortcut

And it will download this shortcut and save it in toml or shortcut format.

Docker

It’s possible to use pre-built Docker container with python-shortcuts inside:

  1. # convert s.toml from the current directory into s.shortcut
  2. docker run -v $(pwd):/files akhmetov/shortcuts-cli /files/s.toml /files/s.shortcut
  3. docker run -v $(pwd):/files akhmetov/shortcuts-cli --help
  4. usage: shortcuts [-h] [--version] [file] [output]
  5. Shortcuts: Siri shortcuts creator
  6. positional arguments:
  7. file Input file: *.(toml|shortcut|itunes url)
  8. output Output file: *.(toml|shortcut)
  9. optional arguments:
  10. -h, --help show this help message and exit
  11. --version Version information

Development

Tests

Run tests:

  1. tox

How to add a new action

See documentation.

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.
  • ☐ Import questions
  • ☐ Document all actions
  • ☐ Support magic variables
  • ☐ Support all current actions from Shortcuts app

Similar projects