haykam821 / ShortcutsPreview

A multiplatform bot for showing the details of Shortcuts when linked by their iCloud URL.
MIT License
33 stars 5 forks source link

Are there any plans to include a small overview of what actions the Shortcut uses? #1

Open jdf221 opened 6 years ago

jdf221 commented 6 years ago

You already have the URL to retrieve the shortcut's plist, so you just need to request it and parse the actions. However, you will need a directory of prettified versions of the action IDs. is.workflow.actions.getwebpagecontents is a Safari action, but the ID definitely doesn't say that.

Why not something like:

Shortcut: Today's Dilbert Strip

Click here to view and get this shortcut.

Here is a list of the actions it uses:

  • Format Date
  • Get Text
  • Get Contents of Web Page
  • Get Images
  • Filter Images
  • Quick Look

ShortcutsPreview v2.0.0 • CreatorSource code

haykam821 commented 6 years ago

There are three reasons why I am not interested in doing this:

However, I am fine with showing the number of actions in a shortcut, such as:

Shortcut: Example Shortcut

Click here to view and get this shortcut.

This shortcut has 6 actions.

I believe there is a list of integrated services that may be possible to list in the body instead, but that has the same problem, where it'd probably just be a list of bundle IDs for the apps that have donated actions.

Hacksore commented 6 years ago

@haykam821 I'm going to take a stab at this. Something simple like a generalized overview of what it's doing, maybe something like the native Shortcuts preview of services/permissions?

image

For instance, if it's using the send message action that should be presented to the end user that it's going to use Messages. We'll see how robust I can get this otherwise maybe the best implementation is to just mention the number of actions like you had previously stated.

haykam821 commented 6 years ago

@Hacksore Can you put the iCloud preview URL here so I can take a look at the overview JSON and file? Thanks for working on this by the way; that's what I had in mind!

Hacksore commented 6 years ago

So the sad part is that the actions payload is not JSON and is some form of encoded text. It should not be that difficult to parse out something like "workflow.actions.[item]" and map a relation the the parent access required.

Fetched from: Here

bplist00�╔╗╚╝║═
_WFWorkflowIconStartColor_WFWorkflowIconImageData_WFWorkflowIconGlyphNumber�╚�@�w��$*,8<>MZ�_WFWorkflowActionIdentifier_WFWorkflowActionParameters_s.workflow.actions.address�
WFCity^WFAddressLine1TUUID\WFPostalCodeWWFStateP_$7A6864C0-EDF7-4FB3-A321-4A5A31E3921B� !_is.workflow.actions.setvariable�"#^WFVariableNameXLocation�%&_(is.workflow.actions.properties.locations�
'()_WFContentItemPropertyNameXLatitude_$8CA1170D-A6DA-412E-A95B-8D82A6ED2C3C� +�"(�-._is.workflow.actions.getvariable�/0ZWFVariable�1237UValue_WFSerializationType�45#6\VariableNameTTypeXVari
able_WFTextTokenAttachment�%9�':;YLongitude_$AD6E0726-6613-4173-992A-B94C8E29F3C4� =�":�?@_is.workflow.actions.alert�AB_WFAlertActionMessage�12CL�DEFGVstring_attachmentsByRangec��
���HIJKV{2, 1}V{0, 1}�45:6�45(6_WFTextTokenString�NO_s.workflow.actions.gettext�PQY_WFTextActionText�12RL�DESTo1 h t t p s : / / w a z e . c o m / u l ? l l =�� % 2 C�� & n a v i g a t e = y e
s & z o o m = 1 7�UVWXW{23, 1}W{27, 1}�45(6�45:6_$CAE0F734-ADB4-4ABC-9162-5648D758E71B�[\_$is.workflow.actions.openxcallbackurlС^XWatchKit�`abcdefghijklmnop_WFAppStoreAppContentItem_WFArticleC
ontentItem_WFContactContentItem_WFDateContentItem_WFEmailAddressContentItem_WFGenericFileContentItem_WFImageContentItem_WFiTunesProductContentItem_WFLocationContentItem_WFDCMapsLinkConte
ntItem_WFAVAssetContentItem_WFPDFContentItem_WFPhoneNumberContentItem_WFRichTextContentItem_WFSafariWebPageContentItem_WFStringContentItem_WFURLContentItem  1 K Z v � � � � � � �╔╝╔ ╔%╔&╔
)╔*╔5╔:╔W╔t╔�╔�╔�╔�╔�╔�╔�╔�╔�╔�╗╗╗.╗7╗<╗g╗l╗�╗�╗�╗�╗�╗�╗�╗�╗�╗�╚ ╚╚╚╚╚╚N╚S╚X╚b╚�╚�╚�╚�╚�╚�╚�╚�╚�╚�╚�╚�╚�╝║╝
                                                                                                           ╝╝╝*╝/╝M╝R╝e╝j╝o╝�╝�╝�╝�╝�╝�║║║F║G║I║R║f║�║�║�║�║�║�══,═D═^═u═�═�═�═�═�      ╗╔
q              ╔

Here is the payload from the iCloud api for a lookup on ID which I'm sure you are familiar with.

// 20180927082202
// https://www.icloud.com/shortcuts/api/records/319212729e2b4d71ad519b2463224e96

{
  "pluginFields": {

  },
  "recordName": "31921272-9E2B-4D71-AD51-9B2463224E96",
  "deleted": false,
  "recordChangeTag": "jmjrzn9k",
  "fields": {
    "icon_color": {
      "value": 431817727,
      "type": "NUMBER_INT64"
    },
    "name": {
      "value": "Wade Direct Navigation",
      "type": "STRING"
    },
    "icon": {
      "value": {
        "fileChecksum": "ASWs9sZbZXARy8I2jIzvkSnc7xtx",
        "size": 171592,
        "downloadURL": "https://cvws.icloud-content.com/B/ASWs9sZbZXARy8I2jIzvkSnc7xtx/${f}?o=AuKdk0KpkOA8gvcITLF_ueVIW0BjjXxqA9H0vZDvJKvrevkTGD-GZqoRS8lh4MS0qw&v=1&x=3&a=Bz4NBLUpx4NPO_B5_ABsaimACcfIA78gRgEAAAODIEY&e=1538058120&k=_&fl=&r=9a9d652f-f0e5-43dd-b4a3-2296cd5fb1ac-1&ckc=com.apple.shortcuts&ckz=_defaultZone&p=33&s=SI2SXIWCozx-sf_Je8sRLHVt7HA"
      },
      "type": "ASSETID"
    },
    "icon_glyph": {
      "value": 59511,
      "type": "NUMBER_INT64"
    },
    "shortcut": {
      "value": {
        "fileChecksum": "AcbSrhpOcTROM03H+o0DNRkaffNo",
        "size": 2051,
        "downloadURL": "https://cvws.icloud-content.com/B/AcbSrhpOcTROM03H-o0DNRkaffNo/${f}?o=ArsLTg3wihy2KOa4V3mCeAX9miqPze6DQpb9wcbTUVVLeQCPAsRneBbhpAt_i5XltA&v=1&x=3&a=Bybo63wwfiUwKZzuibTTpALJPz7iA78gRgEAAAODIEY&e=1538058120&k=_&fl=&r=9a9d652f-f0e5-43dd-b4a3-2296cd5fb1ac-1&ckc=com.apple.shortcuts&ckz=_defaultZone&p=33&s=tv-vfqRKER1tWgn9sIy2QqaWrr4"
      },
      "type": "ASSETID"
    }
  },
  "modified": {
    "deviceID": "2162192A1D6A2A346DB6C7863B1B7F9203B7E87D8C7B5D2883973136879AE33B",
    "userRecordName": "_7b806bb6ec45e5d479cd8e9724d753dd",
    "timestamp": 1538004199313
  },
  "recordType": "SharedShortcut",
  "created": {
    "deviceID": "2162192A1D6A2A346DB6C7863B1B7F9203B7E87D8C7B5D2883973136879AE33B",
    "userRecordName": "_7b806bb6ec45e5d479cd8e9724d753dd",
    "timestamp": 1538004199313
  }
}
jdf221 commented 6 years ago

The shortcut file is a Binary plist file. I believe there is a node library that can read/parse them.

Here it is when it is read correctly: https://gist.github.com/jdf221/281dc14900af053587f87307e3633567

Hacksore commented 6 years ago

@haykam821 Oh and I'm working on adding some functionality to your util shortcuts.js lib first so we can actually get the metadata from a downloadURL.

Stay tuned for a PR.

Hacksore commented 6 years ago

The shortcut file is a Binary plist file. I believe there is a node library that can read/parse them.

@jdf221 Oh in that case there is probably some npm module to convert it from binary to xml/json let me look into this.

haykam821 commented 6 years ago

Yep, it's a plist which can be opened in Xcode just fine and parsed in a module like plist, as long as you give it the proper file association.

Shortcut file opened as plist in Xcode

I still wonder how Shortcuts gets the "works with the following apps and services" list, since it doesn't seem to be included in there.

Hacksore commented 6 years ago

@haykam821 So it seems none of the name libs natively support converting the binary plist file to XML/JSON or they depend on macOS plutil.

Any ideas?

haykam821 commented 6 years ago

I don't know... plists are XML so parse it with Regex? In all seriousness, though, plist-parser says it works with regular JavaScript which should mean it works on Linux and Windows.

Hacksore commented 6 years ago

Normally plists are binary so you need to convert them to XML with macOS plutil or create one in XML first. So, in this case, Apple is distributing them as binary plists. I agree if it was plain XML this would be easy but since it's not we are in this difficult position.

Maybe I'm wrong though?

jdf221 commented 6 years ago

Not able to test it right now, but does this library look like it would work?

https://www.npmjs.com/package/simple-plist

haykam821 commented 6 years ago

Since we are only dealing with binary plists, we can just use this module rather than that one, which parses both types.

Hacksore commented 6 years ago

@haykam821 It worked like a charm 👍

haykam821 commented 6 years ago

@Hacksore Good to know! Do you mind going ahead and opening a pull request on the other repository so I can go ahead and comment on my thoughts for an implementation?

Hacksore commented 6 years ago

@haykam821 Done, see haykam821/Shortcuts.js#3.

JoeCodeswell commented 5 years ago

Hi folks, I made a Python program to convert a .shortcut file (which is a binary plist) into human readable XML. Here is the link https://github.com/JoeCodeswell/shortcut2xml I tested it on windows 10. It seems to work Looking at the XML is helping me understand the structure of Shortcuts. Love and peace, Joe

pfgithub commented 5 years ago

If you want a complete preview of all the actions in a shortcut, I'm working on icloud-shortcut-preview using the shortcut-preview react component,

it shows all the actions of a shortcut the same way the Show Actions button does when you're adding a shortcut in the shortcuts app.

Example: https://preview.scpl.dev/?shortcut=78e1b511a0364586b092e66cfb76e029 where the ?shortcut parameter is the shortcut's icloud id.

haykam821 commented 5 years ago

@pfgithub I've added links to your previewer in 5abcc951db682abd2ce5f8db853e5510a2a36603 (for Reddit) and aede1fa617c6fa050a31fbdcb606176436cb2675 (for Discord). It's not exactly the scope of this issue so I'll leave it open for now. If we go with the 'works with' method, then the preview could have something like:

🔗 Works with Safari, Contacts, and Messages