A shortcut to access another shortcut's comments

Hello there.

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.

https://www.icloud.com/shortcuts/29d64d6e6a0a4a25ab1e950c77cae992

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, …

1 Like

Wow, I had no idea you could access the XML of another shortcut with that set name statement! Nice find! :slight_smile:

As for improvements, two tips:

  1. 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)
  2. 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.

https://www.icloud.com/shortcuts/b03b27f765014eb58e98c613fe1c0ea2

Hope this is helpful. If not, at least I’ve learned a few things myself :slight_smile: (#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.)

2 Likes

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 in advance for insights…

In this case the Set Name action can only receive one file, so it makes you choose which one.

However if OP added a “Choose from list” and then got details of the file they could get the name of the shortcut :wink:

3 Likes

Thanks for the newline tip, but specially for the dictionary access to XML. It’s waaay more cleaner than with regexes :clap:t2::clap:t2::clap:t2: I had to fight a multilevel JSON file recently and ended up hating dictionaries a bit :sweat_smile: You’ve shown me dictionaries are much more flexible than I believed :+1:t3:

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 :grin:

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 :grin: 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 :sweat_smile:

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!) :roll_eyes:

Indeed. Thanks for the tip :slightly_smiling_face:

1 Like

I’ve kept looking into my regex problems, and in the end my problem wasn’t the \n, but the .

The nugget of knowledge I didn’t have is this:

[…] the dot is not a metacharacter inside a character class, […]

Source: https://www.regular-expressions.info/dot.html#n

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) :sweat_smile:

Thanks again for the help,
Antonio

1 Like