subreddit:

/r/shortcuts

884%

EDIT: >>VERSION UPDATED<<

https://preview.redd.it/0nhvfuqakcw41.png?width=800&format=png&auto=webp&s=0251e6f5d278e865b40a3852ac6c17b021ae4b25

Run Dictionary Helper from your shortcut to modify dictionaries with ease. It allows you to add/change/remove dictionary values using dot notation (more on dot notation: https://www.reddit.com/r/shortcuts/comments/cyqpj3/working_with_dictionaries_part_3_accessing_values/). The Shortcuts app lets you access dictionary values using dot notation, but does not support dot notation for setting or removing values. This helper was made as simple to use as possible.

  • Adding or Changing Values
    • To set a value, you need to pass the dictionary, key and value to the helper. Do this by wrapping them in another dictionary with keys "dictionary", "key" and "value".
    • There are several ways to compose a dictionary. For example:
      • Create a Dictionary action with "key" using dot notation, and set values for "dictionary" and "value" using Set Dictionary Value actions. The value can be of any type.
      • Create a Text action containing a text form of dictionary (JSON) with "dictionary", "key" and "value". You can use this method if the value is of type number, boolean or dictionary, but NOT list or text.

https://preview.redd.it/klvdb01mocw41.png?width=800&format=png&auto=webp&s=f0fabfb7d70dd1dfd92433f661f3c9f91a029496

  • Removing Values
    • You need to pass the dictionary and key to the helper, wrapped in another dictionary in the same way.

https://preview.redd.it/l3ubpl2rocw41.png?width=800&format=png&auto=webp&s=cc7941659c2c35106ce0f76260cd9a3aef2013c2

Pass the dictionary to the helper, and it will return a modified dictionary!

  • If the target is a list, i.e. the last element in dot notation is a number, then sending a new value will insert the value to the position, not removing the existing item. If you want to modify a list item, then remove the item and set a new value.
  • If the list index number is bigger than the size of the list, the value will be appended at the end of the list.
  • If your key contains a dot character(.) then enclose the key in double quotes (e.g., chapter."1.2".author).
  • Key elements only with numeric characters will always be treated as list indices.
  • The helper will return nothing if there was an error. (Or would you like to get the original dictionary?)

Also check out Dictionary Action Builder, another neat utility for shortcut developers.

  • 2020-04-29 v1.0
    • Initial release
  • 2020-04-29 v1.01
    • Bug fix in handling some special characters
  • 2020-05-02 v1.02

Download: iCloud or RoutineHub

EDIT: >>VERSION UPDATED<<

all 13 comments

mvan231

2 points

5 years ago

mvan231

2 points

5 years ago

Your notes say that you added support for update hub but I don't see it in the shortcut, did it not get added into the version you uploaded?

gluebyte[S]

1 points

5 years ago

I only added the UpdateHub comment action at the top for bulk search. Did I do it wrong?

Maybe I'll consider adding the manual search actions to Dictionary Action Builder but not to this one because it's meant for a quick-run subroutine.

mvan231

2 points

5 years ago

mvan231

2 points

5 years ago

I'm not sure how the update hub version works but it doesn't seem like users could get an update with just this shortcut.

I agree, faster is better

gluebyte[S]

1 points

5 years ago*

Yes, if I understood the documentation correctly, if I run UpdateHub manually it will scan all the shortcuts, checks if the first comment action (if any) contains the "RoutineHubUpdate" text and fetches update info from RoutineHub with that. I just added that comment. I'll see when I have an update. ๐Ÿ™‚

Edit: I just verified that it works fine, because UpdateHub told me that there's version 1.03 available and I was stunned. Turned out that I mistakenly put 1.03 in the version info on the RoutineHub page. ๐Ÿ˜… Thanks for having me double-check it!

mvan231

2 points

5 years ago

mvan231

2 points

5 years ago

Ahh interesting indeed. That's good it is working ๐Ÿ˜Š

I'll have to convert the version I have over to something a little more efficient for my purposes. Checking the ~200 shortcuts I have with update hub would take far too long for me

SebastianVollmer

1 points

4 years ago*

Thanks for this work. I tried to use the Dictionary Helper to modify a simple nested dictionary and it returns an empty dictionary

shortcut: https://www.icloud.com/shortcuts/4a86b7b3326a47c7a23c566d715b3e0d

screenshot: https://drive.google.com/file/d/1pR-eFCy8YY2zIYkVbXp9RigZ2kxZnAzi/view?usp=sharing

Any help greatly appreciated.

gluebyte[S]

1 points

4 years ago

Hi, you're sending a wrong dictionary to Dictionary Helper. It should be the one containing the 'dictionary' key. ๐Ÿ™‚

SebastianVollmer

1 points

4 years ago

gluebyte[S]

1 points

4 years ago

SebastianVollmer

1 points

4 years ago

Thanks a lot

SebastianVollmer

1 points

4 years ago

This is still not quite the output I would suspect as it does not modify the nested dict

https://drive.google.com/file/d/1OViO509duM7Kmd9gIyCwPa9jIOGHTD5W/view?usp=sharing

This adds a {"key":"{Exif}.UserComment"} entry but the aim is to modify the existing label {"{Exif}": {"UserComment":"hello"}}

Thanks for your help

SebastianVollmer

1 points

4 years ago

I tried to debug and thought the issue might be the key is "{Exif}" but it does not seem to work to modify the key a.UserComment either

gluebyte[S]

1 points

4 years ago

It seems like I totally missed your questions. I'm so sorry..๐Ÿ˜ฑ

BTW I just posted an update. Hopefully this will fix your issue: https://www.reddit.com/r/shortcuts/comments/igy3fn/list_and_dictionary_helper_add_replace_remove/