Any way to get YAML into Shortcuts?

I’m building some automations on my Mac that store data in YAML, in a Dropbox folder.

Is there any straightforward way to get that data into Shortcuts, and keep it reasonably up to date?

The ideal approach would sync both ways, or even better just use the YAML documents as source data. But I’d be fine with updating only when running a shortcut, for example.

I imagine Scriptable could do it, and probably Pythonista. Can DataJar or Toolbox Pro?

Shortcuts has inbuilt access to Dropbox in its file actions, and YAML is just plain text. No additional software would be required.

1 Like

True! But I was hoping for a simple way to turn YAML elements into variables (lists, dictionaries, etc.) that I could then do stuff with — without having to parse them all myself.

1 Like

So, I know Markdown metadata:

  1. Terminated by a blank line.
  2. Key / value pairs, separated by a colon.

How different from the above is YAML?

(Jus thinking how this could be confected.)

They’re very similar. I think one distinction is that YAML key-value pairs can contain types other than strings:

---
Foo: bar
Baz: [1,2,3,"baff"]
Springfield: {"Illinois", "Ohio", "Maryland"}
AlsoAList:
  - one
  - two
  - 3.14159
AlsoADict:
  key: value
  another_key: “another value”
...

Complicating matters: I just discovered that Shortcuts won’t read a plain text file if it has the extension yaml, declaring it an unsupported file type. Despite the fact that iOS seems to be quite capable of identifying a file’s actual type even without an extension.

I genuinely respect anyone who is able to automate iOS or iPadOS in a useful way, but I also do not understand how they do it and remain at all productive. I’m ready to give up. As far as I can tell, it’s only possible if you tie yourself into knots and/or rearrange everything NOT on iOS to work the way iOS does — and even then, it takes at least twice the effort. And nearly all the headache traces back to the fact that iOS was crippled from the outset by not including a user-accessible filesystem, and by deciding that everything is forbidden unless it’s explicitly allowed. It’s fine for consuming media or using other people’s apps (insert all the current debate about the App Store environment and restrictions), but not so much for producing anything much outside that. /rant

You can read such files. If you want to then interact with them as text, you coerce that by changing the extension. Shortcuts tries to do a lot of the hard work in terms of transformation of data, but rather than using say casting or an explicit transformation function as you might in a more traditional programming language, the methods are a little more “fluffy”

E.g. from a .yaml file in a Temp folder in Dropbox containing your YAML example content I could read a setting in like this.

Ok, that’s ingenious, thanks!

I guess I could just repeatedly change the file from .yaml to .txt and then back at the end of the shortcut. Which is bonkers, but better than mirroring files all over the place.

It’s another example of the hoops people have to jump through to work with files and external data. It stunning to think how much more productive people could be if they didn’t have to discover and/or implement these kinds of workarounds.