How to create a pick-list?

This looks great! Just wondering… Where within the script would I change the Group names? And how (and where) would I change the check box names?

BTW, right now, there’s just one check box (CB#1), and the old checkboxes from the last version of the script (#foo , #bar , #baz).

I’m happy to make the changes on my own, but I just don’t want to do anything that will disrupt the script. Like I said, I’m just using the checkbox to copy the checkbox names (and I’m also changes the #'s to @'s).

Thanks so much again for your help!

Right now they are in the HTML code -- hard coded.
The finished script would allow the user to set them in KM Variables.

Gotcha. Thanks for the explanation. Look forward to seeing the finished script - whenever you’re able to complete it! Thanks again for your help…

New user to KM, but this function is essential a big part of why I got the app. I’m also interested in using a pick list in which I can select various hashtags in a list and, once completed, have KM automatically copy them so that I can paste them in another app I use for annotation.

I’ve been able to follow some of the instruction in this post, though there are some images that appear not to work. There are also a few small differences (needs) between the current configuration (as I understand it) and those I’m seeking, namely:

  • When I copy and paste my hashtags, they need to be separated with a comma, but not a comma and space – that is, “,” not ", "

  • Because of the number of hashtags I’m using, I’m wondering if there’s a way to create some kind of separation between them – just to create some defined space between hashtag categories.

  • Finally, I use different sets of hashtags for different projects, so I’m wondering the best way to switch in between hashtags sets – so that I can select & copy different sets of hashtags.

Thanks for your assistance. Appreciate it.

Welcome to Keyboard Maestro! Assuming you're using Keyboard Maestro 8+ (as you most likely are if you've only just downloaded it), there is new functionality in KM8 that makes it possible to use pick lists without requiring a custom HTML prompt (which is what the macro in this thread uses). Here is an example macro I put together that demonstrates two ways of choosing from multiple hashtag sets with nothing but native KM actions that should hopefully be easier to use and customize for your needs. Feel free to ask if you have any questions!

##Download (requires Keyboard Maestro 8)
Hashtag Pick Lists.kmmacros (21.7 KB)

###Prompt for User Input Method

###Prompt With List Method

###Example Pick List


Since KM does not have a prompt that allows you to select multiple items, AppleScript is a good choice to provide this prompt using the choose from list command.

Here is a generic macro provided to give an example of how to build your own macro. You will need to use it as a guide or modify it to meet your specific needs.

##example Output

###MACRO:   Select Multiple Items From List [Example]

~~~ VER: 1.0    2017-11-13 ~~~

<a class="attachment" href="/uploads/default/original/3X/6/2/6273653a8aeab70a59668c379936034dde2e8950.kmmacros">Select Multiple Items From List [Example].kmmacros</a> (15 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**





* **Select Multiple Items from List**
* and format output as comma-delimted string


1. **KM 8.0.4+**
  * But it can be written in KM 7.3.1+
  * It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
2. **macOS 10.11.6 (El Capitan)**
  * KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees.  :wink: 

**NOTICE: This macro/script is just an _Example_**

* It has had very limited testing.
* You need to test further before using in a production environment.
* It does not have extensive error checking/handling.
* It may not be complete.  It is provided as an example to show you one approach to solving a problem.


1. Enter your full list to choose from in the first two Actions
2. Trigger this macro


* **Carefully review the Release Notes and the Macro Actions**
  * Make sure you understand what the Macro will do.  
  * You are responsible for running the Macro, not me.  😉
* Assign a Trigger to this maro.  I prefer TBD.
* Move this macro to a Macro Group that is only Active when you need this Macro.
* ENABLE this Macro.
(all shown in the magenta color)
  * First Two Actions: "Set This to Your List of Items"

TAGS:  @Lists @KM8 @AppleScript


* Any Action in _magenta color_ is designed to be changed by end-user


* To facilitate the reading, customizing, and maintenance of this macro,
      key Actions are colored as follows:
* GREEN   -- Key Comments designed to highlight main sections of macro
* MAGENTA -- Actions designed to be customized by user
* YELLOW  -- Primary Actions (usually the main purpose of the macro)
* ORANGE  -- Actions that permanently destroy Variables or Clipboards,
OR IF/THEN and PAUSE Actions


1.  Keyboard Maestro Ver 7.3+ (don't even ask me about KM 6 support).
2.  El Capitan 10.11.6+
  * It make work with Yosemite, but I make no guarantees.


* While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
* If you have any doubts or questions:
  * **Ask first**
  * Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.


<img src="/uploads/default/original/3X/f/d/fd2016c4a633a939247d309d7174cfb454a195a4.png" width="490" height="1527">



use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property ptyScriptName : "Select Multiple Items From List"
property ptyScriptVer : "1.0"
property ptyScriptDate : "2017-11-13"
property ptyScriptAuthor : "JMichaelTX"


KM VARIABLES REQUIRED: (must be set before calling this script)
• Local__List

KM VARIABLES SET: (by this script)


  1. macOS El Capitan 10.11.6+
    (may work on Yosemite 10.10.5, but no guarantees)

  2. Mac Applications
    • Keyboard Maestro 8.0.4+

  3. INTERNAL HANDLERS (Functions):
    • on getKMVar(pKMVarNameStr, pDefaultValueStr) -- Get KM Variable; set to default if doesn't exist

REF: The following were used in some way in the writing of this script.

  1. How to create a pick-list?
--  Will be either actual results, or Error message
set scriptResults to "TBD"

  set frontApp to path to frontmost application as text -- use for dialogs
  set myList to paragraphs of (getKMVar("Local__List", "") of me)
  ### YOUR CODE HERE ###  
  tell application frontApp
    set selectedItems to choose from list myList ¬
      with title ptyScriptName with prompt "Select One or More Items" with multiple selections allowed
  end tell
  if (selectedItems is false) then error "Use did NOT select any items."
  set AppleScript's text item delimiters to ","
  set selectedItemsStr to selectedItems as text
  set scriptResults to selectedItemsStr -- "OK" as a minimum
  --~~~~~~~~~~~~~ END TRY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on error errMsg number errNum
  if errNum = -128 then ## User Canceled
    set errMsg to "[USER_CANCELED]"
  end if
  set scriptResults to "[ERROR]" & return & errMsg & return & return ¬
    & "SCRIPT: " & ptyScriptName & "   Ver: " & ptyScriptVer & return ¬
    & "Error Number: " & errNum
end try
--~~~~~~~~~~~~~~~~END ON ERROR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

return scriptResults

--    HANDLERS (functions)

on getKMVar(pKMVarNameStr, pDefaultValueStr) --  @KM @Get @Variable
  (*  VER: 2.1    2017-11-13
  PURPOSE:  Get Value of KM Variable & Set to Default if it doesn't exist
    • pKMVarNameStr        | text  | Keyboard Maestro Variable Name
    • pDefaultValueStr    | text  | Default value if Variable doesn't exist
  RETURNS:  KM Var Value
  AUTHOR:  JMichaelTX
  local kmVarStr, isKMErunning
  tell application "System Events" to set isKMErunning to (exists process "Keyboard Maestro Engine")
  if (isKMErunning) then
    if ((pKMVarNameStr starts with "Local") or (pKMVarNameStr starts with "Instance")) then
      --- KM Local or Instance Var ---      
      --  (Requires Keyboard Maestro 8.0.3+)
      set kmInst to system attribute "KMINSTANCE"
      tell application "Keyboard Maestro Engine"
        set kmVarStr to getvariable pKMVarNameStr instance kmInst
      end tell
    else -- normal, global KM Variable
      --     (Requires KM 7.0.3+)
      tell application "Keyboard Maestro Engine"
        set kmVarStr to getvariable pKMVarNameStr
      end tell
    end if -- KM Local or Instance Var
    if (kmVarStr = "") then set kmVarStr to pDefaultValueStr
    set kmVarStr to pDefaultValueStr
  end if
  return kmVarStr
end getKMVar
--~~~~~~~~~~~~~~~ END OF handler getKMVar ~~~~~~~~~~~~~~~~~~~~~~~~~


Hi guys,
Thank you so much for all of this! It looks amazing.
I’m sorry to take a little while to get back to you.

I had to double check with someone who has been providing me with with technical assistance with he hashtags, and he actually advised me to create a comma+space between each value, whereas before I asked for a a comma+NO space between each value.

I’m so sorry about this! Based on his instruction, how should I proceed? Namely, which script should I use and how should make adjustment to achieve the a comma+space between each value?

Thank you so much again!

CORRECTION: The final word is that I need to create a space+comma+space between each value.

I promise there won’t be any more surprises or corrections!

Look forward to your guidance, and thank you all again!

Hi @token12,

Not to worry, this is an easy adjustment to make in either macro. In the one I posted, the two actions to change to make this adjustment are these two:

And in @JMichaelTX's macro, you just need to change one line of AppleScript from this:

set AppleScript's text item delimiters to ","

to this:

set AppleScript's text item delimiters to " , "

Here's an updated version of my macro with the changes in place (boxed in red in the image). Feel free to ask if you have any further questions!

Hashtag Pick Lists 1.1.kmmacros (21.5 KB)

1 Like

@gglick, thanks for taking care of this! Much appreciated. :+1:

1 Like

Thanks so much for this, and sorry for my late reply!

It seems like JMichaelTX’s script is closer to what I’m seeking.

Let me back up a sec… These pick lists are for individual annotation-related projects. Each pick list contains a set of hashtags that are tailored to a specific project (i.e., particular events, people, research issues, etc.).

I’m trying to use one pick list for an annotation-related project at a time. So, I won’t need to be constantly toggle between different lists as part of using the KM pick list macros you guys have kindly put together. Instead, I need to select one list, use it repeatedly, and then swap it out with another list when I turn my attention to a different project. Therefore, it doesn’t seem necessary to have the first output set up to repeatedly choose between list sets. Make sense? Is this possible to change it so that I’d be able to change it once when I switch to another pick lists?

By the way, I’m also creating some definition within these pick list by categories, with titles (e.g., EVENTS, PEOPLE, RESEARCH ISSUES, etc.) to segment the different hashtags. It seems I can do that within JMichaelTX’s script.

Anyway, the only other requested change to this would be instead of displaying the selected hashtags, I’d love to just copy them – so that I could then paste them into the app that I’m using with this script (which is MarginNote).

Would it be possible to make these changes to the script?

Thanks so much again for all of your help! I greatly appreciate it, as always…

You can easily customize the macro I posted to achieve this.
Just disable/delete the Prompt for User Input and set the desired list using a Set Variable to Text action.

Again, something you can easily do.
Just replace the Display Window with a Set Clipboard Action.

Ok, I tried this and thought I got it. But when I tried to execute the script, the disable function seemed to disable the entire Macro. What did I do wrong?

Sorry, I didn't get this one, either. I don't see that option. Right now it's set as "Display text in a window," but there aren't any option that approximate "Set Clipboard Action" in the dropdown. I've tried to find "Set Clipboard Action" when I click on "Insert Token," but don't see anything there, either.

I'm sure I'm overlooking something or am not quite grasping your instructions. Just let me know when you can and I'm sure I'll figure it out.

Thanks again!

Select the Action, and click on the Gear menu, then select "Disable"

Please explore the KM Actions (KM Wiki) list.

Ok, but when I do that it seems to disable the who script - not a portion of it.

I can only guess that you must be disabling the entire macro by mistake, as it's definitely possible to only disable individual actions. Here's a slightly modified version of @JMichaelTX's macro with the prompt and Display Text actions disabled and a final additional action using Set Clipboard to Text:

Select Multiple Items From List [Example] 1.0.1.kmmacros (15.4 KB)

You can either download and use that, or just reference the image as a guide for how the macro should look in order to achieve the results you want.

Thank you so much for sending this! Unfortunately, when I create a new trigger and / or click on Try at the bottom of the window, it doesn’t do anything.

I’m sorry if I’m missing something elementary. I’m trying my best to make this work, and thank you for all of your help. Truly.

BTW, I should add that when I click on Edit again, I see that the title of the Macro reads:

Select Multiple Items From List [Example] 1.0.1 (Disabled)

Not sure why…

No worries; we all start out in an elementary state :slightly_smiling_face:
You're far from the only one to be confused about what the "Try" button at the bottom of the editor does. Rather than execute the whole macro, the "Try" button only executes the currently selected action. The button to execute the entire macro is actually this one:

This is because Keyboard Maestro imports new macros in a disabled state by default, for security purposes. Both the macro group and the macro itself need to be enabled before the imported macro can be executed. Disabled macro groups and macros are shown in faded-out gray:

###Disabled Macro Group

###Disabled Macro

You can enable them by selecting the group or macro and clicking on the corresponding checkmark button at the bottom of the editor:

Once enabled, they should look like this:

###Enabled Macro Group

###Enabled Macro

You can also confirm whether a macro group or macro is enabled or disabled by the large X or √ in the top right corner of the Edit pane:

###Disabled Macro

###Enabled Macro

Once both the macro and its macro group have been enabled, the trigger you assign to the macro should work as expected, or you can use the "execute entire macro" button to try it without needing to set a trigger.

@token12 I'm afraid I just realized that the 1.0.1 version of the macro I uploaded earlier wouldn't work even if it was properly enabled because it needed some more slight tweaks to accommodate only using one list at a time. Here's a new version that I've confirmed works as intended:

Select Multiple Items From List [Example] 1.0.2.kmmacros (17.1 KB)