I am new to KM, so please excuse me if the question is too simple. I searched the forum for an a anwser but could not find anything I could use.
I want to create a KM action dialogue that would display a list of possible commands from which to choose, such as the Prompt with List action, or the beatiful Spotlight Search macro library, but then also allow for freeform text following the command name.
I.e. a dialogue that shows a list
Macro Type 1
Macro 1
Macro 2
Type 2
Macro 2.1
M 2.2
and the input field and then the user can select a macro by typing as in the Prompt with List action but once only a single macro is left the user can continue typing the macro parameter string.
As return value I would like the selected macro name and the rest, or the selected macro and the entire user input so that I can filter the string into macro and parameter myself.
It seems like something that has been done before and I know I can probably do it using Custom HTML prompt, but I don’t know javascript (only applescript and python), so I don’t know how to use that for what I want to do.
Not to worry. There’s no such thing as a too-simple question around here, and I don’t think yours falls into that category anyway
If you’re using Keyboard Maestro 8, which you almost certainly are if you just started using KM and have used Prompt With List before, you can use the Trigger Macro by Name action and pass freeform text to the selected macro by including // at the end of your search string. The selected macro will be executed, and anything after the // will be sent to the macro as a parameter, and is accessible via the %TriggerValue% token. Also new to KM8 is the ability to restrict Trigger Macro by Name to certain macro groups or active/enabled macros only, so you should be able to arrange things so that only the macros you want to see for this dialogue are presented.
If you have any further questions, or you don’t think this would quite fit your needs, don’t hesitate to ask
Slight aside, but I was wondering yesterday how feasible it looks to add an option to Peter’s excellent new Prompt with List action, allowing it, where needed, to accept new strings in addition to those in the list.
Many thanks for your response. This indeed solves the problem I had. Many thanks!
Admittedly, there might be visually more appealing methods, along the lines you suggested (extending the Prompt with List) but then, who cares.
My main appliction was to completely automate Apple Mail, i.e. I have a bunch of macros for various response types and for filing mail accoding to their type. (I.e. new review triggers creating a new mail folder, adding a deadline to my todo list manager, adding the mail to devonthink (which I use for information storage) etc etc and then move the mail to the new mailbox. Most of it is with applescript but I don’t know how to do dialoges in apple script also )
So your anwser really is the simplest possible solution to do exactly what I want.
Your basic AppleScript dialog is easy enough. Here's the syntax.
set theResult to display dialog unicode text ¬
default answer unicode text ¬
hidden answer boolean ¬
buttons {unicode text, ..} ¬
default button unicode text | integer ¬
cancel button unicode text | integer ¬
with title unicode text ¬
with icon unicode text | integer ¬
with icon stic ¬
with icon file ¬
giving up after integer
More is possible with AppleScriptObjC libraries Shane Stanley has written:
I know that the applescript mail lib is not working well, I spent a good portion of time to figure this out
When I say applescript I actually mean python with an applescript wrapper I programmed for the apps I use, so the broken mail stuff I do in python directly.
KM is then used to trigger scripts, ask for my input and activate menu items etc which is much easier here than anywhere else. A really great program, KM.
Having said that, here is another question.
Is something like gglick’s solution also possible without triggering a macro? Say I want a list of options to choose from but than also to enter some freeform text after //. Say a deadline or so.
Can this be done? The Prompt with List does not seem to do it.
This isn’t currently possible with Prompt With List, but I can easily imagine a workaround with the standard Prompt for User Input that includes a dropdown list and a freeform text entry field where the macro checks to see if the freeform text’s variable is empty or not and does something with the text if it isn’t. However, I’m having difficulty imagining the kind of use-case you would need this for. If you can provide a more specific example of what you’re trying to accomplish, then we might be able to come up with a suitable solution.
Here is my usecase: I get emails asking me to review a scientific paper. This can be for a conference, a phd thesis, a journal etc.
I have different mail folders for different types of reviews. So when I get such an invitation, I activate a macro which ideally would display the list of possible review types (to avoid typos reasulting in new mail folder confrences etc) and by typing I select an entry but then once this is done I’d like to continue after the // to input name and deadline.
Say I’d type "confe//*
to select the “conference” review type and supply the name and deadline.
Splitting at // and * I know how to do.
Another use case would be committee meetings. There is a fixed selection of committees I choose from but the deadline and further info is free form.
I know I can get a working solution by having one dialoge after the other, which is fine, but I would find it more convenient to be able to input all in one go.
Of course another good solution would be to use a free form text field and input the command and then parse it later. Probably this is what I will do, but if something better existed already, it would be nice.
Thanks, Stephan! I think I understand your use-case better now. Unfortunately, I still don't think you have any options that do exactly what you want; the closest I can think of is to use several similar macros for each of your purposes, like a group for reviews and a group for committee meetings, and treat each group like a single macro by creating a Trigger Macro by Name macro for each one. That would give you all of your options in a format similar to Prompt With List with the ability to pass on parameters with //, but of course, the tradeoff would be multiple macros to manage instead of one.
That said, there is one more thing I can think of to make this idea more feasible; in order to reduce redundancy and keep a system like this as close to a single macro as possible, you could create one macro that's meant to be used as a sub-macro and keep all the actions that would be the same across macros there. Then, in either the review group, or committee meetings group, or any other macro group you cared to make, you could just add the details you need for each type and have the sub-macro handle the rest. If you haven't already done so, you can download Spotlight Search Prompt to see several examples of this kind of system in action, as the key macro there is relegated to a single sub-macro and all of the example macros call it to perform their various functions. In lieu of a Prompt With List that allows for passing through parameters the way Trigger Macro by Name does, I really think this solution (one core sub-macro and multiple macros for your respective use-case that execute it) might be the closest facsimile to achieving what you want. Feel free to ask more questions if anything I've described here is unclear or you could use help setting up a system like this!
Agreed! I used KM for years before frequenting this forum, but once I did my understanding and usage really started to take off. I've learned a lot of valuable and useful things here, so I'm glad to be able to help others in turn, even if my knowledge still pales compared to the true gurus
Your requirements are fairly complex, and the processing needed is sophisticated. I suspect a Custom HTML Prompt action (KM Wiki) combined with some JavaScript processing would be needed.
There are probably some JavaScript libraries that already do much of what you want. Fortunately, the KM HTML Prompt can make use of JS libraries, if properly setup.
Sorry, but this idea is all I can offer at the moment.
I don’t want to drag this out any further since you’ve already answered my question and I have a working solution in place now using the Trigger Macro by Name action and a separate macro for each type of review etc. That works well, there are only few types of reviews and otherwise generating new macros could be automated also I guess
But I do not quite understand Michaels reply, that’s why I am asking again.
Actually, my workflow is not complex at all, I think I made it look more complicated than it is.
What I wanted was the “Trigger Macro by Name” action but without the trigger. I.e. instead of passing it a list of macros I want to give it a list of text lines. Otherwise exactly the same should happen, i.e. by typing select a line but allow for the // which is then returned in the same way as the “Trigger Macro by Name” does it.
So I would not need any conceptionally new action.
But like I said, I am very happy with how it works now.
Perhaps I'm the one who is making your needs overly complicated, but I was just going on what you had provided us.
So, if you're happy with what you have, then you can ignore the rest of this post.
But, if you'd like to try again, then I'm willing to work with you.
I would need for you to be very thorough, and very precise in what you post. Try to think of what you write as something to be read by someone who has no idea of what you want, or what you current workflow is. Because that is truly the case. Don't make any assumptions, and don't use any special terms without defining them.
Next, I need a complete, real-world, example set of data. Put this data in a code block, like this:
####How to Put Script in a Forum Code Block
Just insert your script between the lines with the triple backquotes:
```text
```text
-- Your data Here
```
```
Now, step by step, list exactly what you want to see, and what you want to type.
Then, when you make a selection, list the fields you want to fill in, or be processed in some manner.
Finally, show the final result of what you want the results to look like.
I have some ideas using [MACRO: Spotlight Search Prompt](https://forum.keyboardmaestro.com/t/macro-spotlight-search-prompt/4665) by @DanThomas, but I won't know for sure until I see your details.
If you don't won't to bother with all this, and stick with what you have, then that's fine too.
Awaiting your decision . . .