Giter Club home page Giter Club logo

python-shortcuts's Introduction

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:

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

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

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

Or the same with Python:

from shortcuts import Shortcut, actions


sc = Shortcut()

sc.actions = [
    actions.AskAction(data={'question': 'What is your name?'}),
    actions.SetVariableAction(data={'name': 'name'}),
    actions.ShowResultAction(data={'text': 'Hello, {{name}}!'})
]

How to use

Installation

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:

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.

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:

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:

# convert s.toml from the current directory into s.shortcut

docker run -v $(pwd):/files akhmetov/shortcuts-cli /files/s.toml /files/s.shortcut


docker run -v $(pwd):/files akhmetov/shortcuts-cli --help

    usage: shortcuts [-h] [--version] [file] [output]

    Shortcuts: Siri shortcuts creator

    positional arguments:
      file        Input file: *.(toml|shortcut|itunes url)
      output      Output file: *.(toml|shortcut)

    optional arguments:
      -h, --help  show this help message and exit
      --version   Version information

Development

Tests

Run tests:

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

python-shortcuts's People

Contributors

alexander-akhmetov avatar dependabot-preview[bot] avatar jon77p avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-shortcuts's Issues

KeyError: 'VariableName'

Running in Pythonista 3 on iPad. Installed all the dependencies using the Stash add-on for Pythonista.

Traceback (most recent call last):
  File "/private/var/mobile/Containers/Shared/AppGroup/F82F97C6-B15F-41D4-B735-B51241CB9688/File Provider Storage/Repositories/python-shortcuts/shortcuts.py", line 5, in <module>
    main()
  File "/private/var/mobile/Containers/Shared/AppGroup/F82F97C6-B15F-41D4-B735-B51241CB9688/File Provider Storage/Repositories/python-shortcuts/shortcuts/cli.py", line 56, in main
    convert_shortcut(args.file, args.output)
  File "/private/var/mobile/Containers/Shared/AppGroup/F82F97C6-B15F-41D4-B735-B51241CB9688/File Provider Storage/Repositories/python-shortcuts/shortcuts/cli.py", line 18, in convert_shortcut
    sc = shortcuts.Shortcut.loads(sc_data, file_format=shortcuts.FMT_SHORTCUT)
  File "/private/var/mobile/Containers/Shared/AppGroup/F82F97C6-B15F-41D4-B735-B51241CB9688/File Provider Storage/Repositories/python-shortcuts/shortcuts/shortcut.py", line 53, in loads
    return cls._get_loader_class(file_format).loads(string)
  File "/private/var/mobile/Containers/Shared/AppGroup/F82F97C6-B15F-41D4-B735-B51241CB9688/File Provider Storage/Repositories/python-shortcuts/shortcuts/loader.py", line 69, in loads
    shortcut.actions.append(cls._action_from_dict(action))
  File "/private/var/mobile/Containers/Shared/AppGroup/F82F97C6-B15F-41D4-B735-B51241CB9688/File Provider Storage/Repositories/python-shortcuts/shortcuts/loader.py", line 85, in _action_from_dict
    for p, v in action_dict['WFWorkflowActionParameters'].items()
  File "/private/var/mobile/Containers/Shared/AppGroup/F82F97C6-B15F-41D4-B735-B51241CB9688/File Provider Storage/Repositories/python-shortcuts/shortcuts/loader.py", line 86, in <dictcomp>
    if p in shortcut_name_to_field_name
  File "/private/var/mobile/Containers/Shared/AppGroup/F82F97C6-B15F-41D4-B735-B51241CB9688/File Provider Storage/Repositories/python-shortcuts/shortcuts/loader.py", line 115, in deserialized_data
    return deserializer(self._data).deserialized_data
  File "/private/var/mobile/Containers/Shared/AppGroup/F82F97C6-B15F-41D4-B735-B51241CB9688/File Provider Storage/Repositories/python-shortcuts/shortcuts/loader.py", line 134, in deserialized_data
    return self._data['Value']['VariableName']
KeyError: 'VariableName'

name: str = '', ^ SyntaxError: invalid syntax

File "/Library/Python/2.7/site-packages/shortcuts/shortcut.py", line 22 name: str = '', ^ SyntaxError: invalid syntax

Keep getting this.

Tried to run the example python as a script to produce the .shortcut

A project with a similar scope

Hey Alexander! ๐Ÿ‘‹

I've just been pointed your way by this thread on r/shortcuts and I thought I'd drop you a message. I know that an issue isn't the best place for this, but hey ho!

I've just released Shortcuts JS which has a very similar scope to python-shortcuts, but is implemented in JavaScript rather than Python. As the projects have such a similar scope, there may well be things that can be learnt from one another's projects, so I thought I'd just introduce myself and point you in the direction of the repo, on the off chance there's something there you find interesting or useful.

I can already see that python-shortcuts implements some additional features that I'm hoping to add to Shortcuts JS at some point, mainly the shortcut โ†’ toml feature, which in my case would likely be shortcut -> JSON, or possibly shortcut -> JS.

Anyway, keep up the great work!

url error

shortcuts https://www.icloud.com/shortcuts/f50e51246720489c85d01149694b214b b.toml
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/bin/shortcuts", line 13, in
load_entry_point('shortcuts==0.10.0', 'console_scripts', 'shortcuts')()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/cli.py", line 79, in main
convert_shortcut(args.file, args.output)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/cli.py", line 34, in convert_shortcut
sc = shortcuts.Shortcut.loads(sc_data, file_format=shortcuts.FMT_SHORTCUT)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/shortcut.py", line 53, in loads
return cls._get_loader_class(file_format).loads(string)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/loader.py", line 71, in loads
shortcut.actions.append(cls._action_from_dict(action))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/loader.py", line 88, in _action_from_dict
for p, v in action_dict['WFWorkflowActionParameters'].items()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/loader.py", line 89, in
if p in shortcut_name_to_field_name
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/loader.py", line 120, in deserialized_data
return deserializer(self._data).deserialized_data
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/loader.py", line 145, in deserialized_data
f'Unknown token attachment type: {field_type}',
shortcuts.exceptions.UnknownWFTextTokenAttachment: Unknown token attachment type: ActionOutput


sudo shortcuts https://www.icloud.com/shortcuts/c92f72b4f82d4f09bb3e7f60d690a1d9 a.toml
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/bin/shortcuts", line 13, in
load_entry_point('shortcuts==0.10.0', 'console_scripts', 'shortcuts')()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/cli.py", line 79, in main
convert_shortcut(args.file, args.output)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/cli.py", line 34, in convert_shortcut
sc = shortcuts.Shortcut.loads(sc_data, file_format=shortcuts.FMT_SHORTCUT)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/shortcut.py", line 53, in loads
return cls._get_loader_class(file_format).loads(string)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/loader.py", line 71, in loads
shortcut.actions.append(cls._action_from_dict(action))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/loader.py", line 81, in _action_from_dict
action_params=action_dict,
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/shortcuts/actions/registry.py", line 75, in get_by_itype
raise exceptions.UnknownActionError(itype, action_dict=action_params)
shortcuts.exceptions.UnknownActionError:
Unknown shortcut action: "is.workflow.actions.choosefromlist"

        Please, check documentation to add new shortcut action, or create an issue:
        Docs: https://github.com/alexander-akhmetov/python-shortcuts/tree/master/docs/new_action.md

        https://github.com/alexander-akhmetov/python-shortcuts/

        Action dictionary:

        {'WFWorkflowActionIdentifier': 'is.workflow.actions.choosefromlist', 'WFWorkflowActionParameters': {'WFChooseFromListActionPrompt': 'ๅŠ ๅฏ†ๅฎ‰ๅ…จๆ€ง๏ผŸ', 'CustomOutputName': 'Security Type', 'UUID': 'C704598C-0FB2-49D6-A04A-DBB4D29755E1'}}

Run_shortcut not working

I am having a problem getting the run shortcut action to work. I have it formatted like this.

[[action]]
type = "run_shortcut"
shortcut_name = "UpdateKit"
show = "False"

I get the error:
<class 'shortcuts.exceptions.UnknownActionError'>:
Unknown shortcut action: "run_shortcut"

Issue installing package

When trying to install the package I am getting the following error:

pip install shortcuts
Collecting shortcuts
  Using cached https://files.pythonhosted.org/packages/f1/cb/1924e5814706a0ef9140c0399c82a6a1257fb84756cd838684fd61732701/shortcuts-0.10.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Will\AppData\Local\Temp\pip-install-_62p5ag4\shortcuts\setup.py", line 19, in <module>
        readme = f.read()
      File "c:\users\will\python\lib\encodings\cp1252.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 277: character maps to <undefined>

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Will\AppData\Local\Temp\pip-install-_62p5ag4\shortcuts\

I've tried updating setuptools and have tried running as system admin to no luck

Windows 10 Home x64 happening on both Python 3.7.2 & 3.6.8

List of every action built into shortcuts and their parameters

If you want to be able to add actions more easily, @xAlien95 extracted a plist of all the actions in shortcuts 2.1.2,

https://raw.githubusercontent.com/pfgithub/shortcutslang/33a323c0d0356dd51730580a6574ab86431f10c6/src/Data/Shortcuts%202.1.2.json

It's missing some things like the blocks in if, choose from menu, repeat, and repeat with each. It also doesn't list any arguments for the Get Details of * and Filter * actions. It should make it easier to add actions, or if you want to it makes it possible to automate adding them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.