I’ve done a shortcut that extracts the text of a shortcut’s comments. It also serves as an example of how to access a shortcut’s content. I have had some problem with regular expressions and with multi-line comments. That’s why I had to “chop” the process and introduce several text replacements. If someone finds out how to do it without them, I will appreciate any help.
I’m thinking about saving the metadata of the shortcut in a comment (a-la-userscript) and access it like this. Think name, version, author, download/update URL, dependencies, …
Wow, I had no idea you could access the XML of another shortcut with that set name statement! Nice find!
As for improvements, two tips:
You can use a newline in Match Text by just pasting a newline character (type one in a comment-box or something and copy/paste it)
You are now parsing XML using regular expressions, which is probably not the best way to do it. It can be done of course (as you have demonstrated), but Shortcuts actually supports plist XML files
So another way to do it would be using dictionaries. I took a stab at it and think I’ve replicated your functionality, without regex, using dictionaries.
Hope this is helpful. If not, at least I’ve learned a few things myself (#1 being how to get to the XML of another shortcut. Not sure how I would use this yet, but I imagine it might be helpful sometime.)
Very interesting. Can somebody explain the Set Name action in more detail? The description in the action itself is vague. What characteristic causes use in this shortcut to prompt you for a choice?
I would love to understand more about what is behind the Set Name action. Black box for me!
Thanks for the newline tip, but specially for the dictionary access to XML. It’s waaay more cleaner than with regexes I had to fight a multilevel JSON file recently and ended up hating dictionaries a bit You’ve shown me dictionaries are much more flexible than I believed
I found the “Set Name” hack here, when trying to access XML as text. Knowing that, it was a question of trying different extensions and checking the results
Not sure how I would use this yet, but I imagine it might be helpful sometime
It was a “is this possible?” moment while insomniac that came from thinking about storing metadata in the shortcut (would that be de-metaing the metadata?).
For example you could have a list of auxiliar shortcuts required in a comment, in an specific format. Then you could have a variation of my shortcut looking for and reading those special comments and checking if all of them are available, and if not, offer to install them.
Or maybe an external update checker without any performance penalty (extra actions) in the updateable shortcuts.
For now all this it’s just on the hey-it’s-possible state
I don’t know much more than what my shortcut shows. Different file extensions seem to change the type of data. I found a .txt extension allowed me to access the text of an XML file, and then I keep experimenting with it, and found out that a .plist extension gave me access to the XML of a shortcut. G*d knows what othre combinations are there.
We really need proper documentation of each shortcut action (at least the system ones!)
Now I have two versions of my comment-peeking shortcut. One with regexes (much simpler than the original) and the other with dictionaries (both 20 actions or less)