Dictionary to Picker to Pythonista/Scriptable to API?

Hello,

I want to try to learn Shortcuts (better than just using it to just open an app), and so I want to take a simple task (create web interface and log to DB), and do that in Shortcuts. The plan is to create a medication logger, so thus far I have:

  1. Entered a k,v dictionary of medications, e.g. (1: Claritin, 2: Zyrtec, …)
  2. Choose from Dictionary, and
  3. Show “Chosen Item”

Ideally, once I have chosen the item from the dictionary, I would send the choice to Scriptable or Pythonista to call the remote API to log the item. With requests, this becomes almost a one-liner in Pythonista, but I may try Scriptable to beef up the JS skills too.

Questions:

  1. Is there a way to have the Chooser (step 2) show the meds in large type and the key in small type (or not at all),

  2. Once picked, how do I get the key, rather than the value from the dictionary? Right now my step 3 shows the name of the medication, when all I would want to pass would be the key.

  3. Am I on the right path, or is there a better way?

  4. I’ve looked at some other examples linked from this site. Is there a way to view the steps of a Shortcut on the web (Macbook), rather than having to download it to my phone?

Thanks for any guidance!

  1. Assuming, from your example, that your keys are the numbers, you would need to restructure your dictionary to use the names as keys and numbers as values to display the names in Large type. { "Claritin":1, "Zyrtec": 2 }
  2. If you restructure like what I said above, you’ll get the number.
  3. There is more that one way to do the same but I think you have the simplest one.
  4. https://showcuts.app/

I like both Pythonista and Scriptable but I’m using Scriptable. Specially now that it has as a Run Inline Script shortcut action, the flow is smoother without the app switching.

1 Like

In Shortcuts, no. In Pythonista, you could build a custom UI. In Scriptable, generally no, but you can bodge together a web page based UI that might be able to do something like that.

If you have got the key, use the key to read the value of the key from the dictionary using the ‘Get Dictionary Value’ action.

Shortcuts can make web API calls, so you could make it from there. Likewise, you might be able to do the whole thing from Scriptable, and I’m sure you can in Pythonista. While you can switch and jump between apps, I would suggest that you may not need to.

There is a web app that’s a rather expensive (in my opinion) subscription, that allows you to edit steps. If you just want to preview, then there are a couple I think that will let you do that.

:+1:

I stand corrected. I’d never noticed that if you pass a whole dictionary in to a choose from list that it has a title and subtitle style display.

Well jeez, sometimes we overlook the simplest things! I’ll reorganize the dictionary as above. Thank you both for your responses. I’ll trudge on and see how things go!

I also would like to access the selected key of a “Choose From” dictionary call.

I don’t quite follow this response:

I understand how to get the selected dictionary value (or look one up from a key), but am not sure how to get the selected key?

Maybe this example will help?

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

1 Like

That’s very clever… Choose From ‘Keys’ vs Dictionary.

Perfect, thank you.