Writing a script to autocomplete from a list selection

Hi,

I’m trying to write a script which lets the user select an item from a list of around a hundred items. The search box should autocomplete as the user enters text. I’ve done much searching on the Internet, but the majority of options I’ve found require references to an HTML element which stores the list, which I’m guessing is not applicable in Drafts.

Any advice much appreciated!

Many thanks,

Martin

The Prompt script object is used for getting user input, but the prompt documentation lists nothing for that sort of autocomplete. Therefore, you would probably need to consider calling out to a separate app to offer this functionality.

On i*OS, Shortcuts doesn’t offer this, but might be Bale to do something based on HTML with a web view. Scriptable certainly could, and I suspect Pythonista probably could offer something with its UI builder, but I haven’t checked to confirm this.

On macOS, you would need something that allows for URL calls, but that’s a pretty wide field. AppleScript is coming for Drafts and would open up some other options around this on the Mac.

1 Like

Thanks. I’ve heard of Scriptable, and I think I need to head in that direction.

This is what script filters in Alfred do — they update results by running the script after every keystroke. I’ve yet to find an equivalent on ios.

1 Like

I still run some of my actions through Editorial just to make use of list option autocompletion. Also: I will always love that app, so any excuse to continue using it makes me happy.

I may be misinterpreting what the OP is asking for, but isn’t this kind of autocompletion available via the “Choose from list” scripting option in Shortcuts?

Would be nice (read: cleaner, smoother experience) to have it within Drafts, though… :wink:

1 Like

Choose from list displays a list you can tap on for selection. There isn’t a field which allows you to start typing text and filtering the list for a string that matches.

For what it’s worth, @martinperry posted a Scriptable based query on this over on the Automators forum. I ended up posting a solution to it there for producing such a list in a web view and how to call and pass back the selection to Drafts. That seemed to meet the requirements by the looks of it.

1 Like

Isn’t this what the search field at the top of the list does?

1 Like

That looks like the search built into the app for searching for shortcuts rather than the choose from list in Shortcuts that can be utilised for automations, which as far as I can tell has no search field.

1 Like

Hm. Tried your example myself, and true: no search bar. But if you flick the “search multiple” setting active… search bar!

Also: if you’re choosing from a list of externally held items (e.g. items returned from a Drafts query or Trello) you don’t even need to activate the “search multiple” setting. Not sure exactly why that makes a difference, but not complaining. True, this has to be run in-app rather than from a widget or anywhere else…

(Again, please forgive if I’m missing the point of what the OP was actually asking for…!)

Much as I appreciate this functionality, I’m not loving the UI so much. Keen to experiment with other options that make this kind of menu building feel a little less hacked together.

2 Likes

I think multiple selection is a bad option for a single select list, but if only for an individual’s use then it could be a viable approach. It is just very strange that the select multiple is required to enable it. It seems the same is true for some other data types as well as text (e.g. contacts), but for some others, including internal ones like reminders, it does show the search.

A baffling variation in behaviour :man_shrugging:t2:

2 Likes

Ahhhh! Was just playing with a new shortcut based on a Drafts workspace and realised the mistake in what I’d suggested. If “select multiple” isn’t selected, I think the search box appears for lists that have more than 10 items?

2 Likes

Confirmed - definitely a useful thing to know! Thanks for highlighting :+1:t2:

2 Likes

@dfay @jsamlarose @sylumer My main aim was to select items from my favourites in AnyList. I have decided to go with the shortcut below called from within Drafts. It doesn’t have autocomplete (and I need to manually recreate my favourites as a list within the shortcut) but it works well for me. It also allows for multiple selection.

Thanks for all your help!

Martin

@sylumer: FYI, this functionality is currently not present in iOS14. I very much hope that’s a temporary state of affairs…

1 Like

These last couple of years Shortcuts betas have been all over the place. Great stuff, but more issues than I would expect for beta.

Even on i*OS13 today I still have problems in that Siri has never been able to run a Shortcut by name on any device, and when opening a new shortcut it always takes a minute or two (not a figurative minute, an actual minute) before I can search for actions and have any returned. These have been issues since the start for me and I purposefully didn’t do the betas last year or this because of the volumes of issues I’ve seen; and I beta test for over a dozen app developers on Mac and i*OS all the time.

I’d been hoping for a stability release with 14, but anecdotes like this make me fear that things will simply get worse :pensive:

1 Like

This could be a good use for the MGCheckList library, which can filter or select based on typing a few letters of a list item …

2 Likes

Indeed— MGCheckList prompts completely fulfil my “list prompt with filter” needs in Drafts these days… :wink:

One thing I haven’t yet done is use an MGCheckList as a menu for actions that begin/end outside of Drafts. I still use Editorial like this, occasionally. I imagine it wouldn’t take much to make that switch, though.

1 Like

Could that library be easily adapted to Scriptable for general use in Shortcuts outside of Drafts?