Paste Checked Items

I would like to create a macro that list items with check boxes, and then the checked items are pasted in a document. I see where you can do checked item, but I can't figure out how to get the checked items pasted.

I took a look this possible solution, but involves inputting text. I don't want that.

thanks

If you use the Prompt for User Input action (https://wiki.keyboardmaestro.com/action/Prompt_for_User_Input) to create your checkboxes, you will at the same time be creating variables for each of those checkboxes.

It is the variables you will want to paste by using the Insert Text by Pasting action (https://wiki.keyboardmaestro.com/action/Insert_Text_by_Pasting), although there are other options (https://wiki.keyboardmaestro.com/action/Insert_Text) too.

Thanks, mrpasini. Yeah, variable and pasting actions are where I'm getting stuck. Here's what I have so far. I know the numbers are for the check boxes, but how do I get the macro to paste the selected name?

I think you may have inadvertently overthought this :slightly_smiling_face:
Just have the last Insert Text action paste the actual name instead of the variable:

1 Like

Not sure what you mean. I should of added that I want to have say about 10+ names with a checkbox for each. And I might say check four or five of those names and have them pasted. How might that work?

In that case, what you need to do is assemble a variable with all the names you want by repeating an If/Then for each. Here's an example:

Paste Names via Checklist.kmmacros (4.0 KB)

Although you can't see it in the image, please note that there is a line break after the names in the If/Then actions to ensure that each name gets added on its own line rather than all on the same line. I also used a local variable for "NamesToPaste" because "NamesToPaste" needs to start fresh every time this macro is run, or else you'll end up with repeats and doubled names. If you haven't yet upgraded to KM8, you'll need to make sure to set "NamesToPaste" to %Delete% at the end of the macro.

1 Like

Oh wow, thank you so much for putting it together. I can’t wait to get this try tomorrow morning. I’ll study it to understand what I was missing. Really appreciate it. And yes, I’ve upgraded to KM 8

1 Like

A good way to make this clearer is to use %Return% so it is visible.

1 Like

This question ended up tickling the engineer part of my brain even after I made the earlier macro, and I was compelled to see if I could improve on it. Fortunately, thanks to @peternlewis's help, I was able to significantly improve it by eliminating the need to manually add new If/Then actions for every name added to the checklist. With this version, all you have to do is ensure that you prefix your name variables with Name__ (don't worry, the two underscores ensures that they'll still look like just the names in the prompt) and the macro will do the rest. If you're going to study a version of the macro, this is the one to do so :slightly_smiling_face:

Paste Names via Checklist 1.1.kmmacros (4.8 KB)

Here is another method, which shows how a little AppleScript can go a long way.
I found the script to be simpler/shorter than the equivalent KM Actions.

AppleScript To Get List of Checked KM Variable Names

property ptyScriptName : "Get List of KM Variable Names with Prefix and Value"
property ptyScriptVer : "1.0"
property ptyScriptDate : "2017-10-12"
property ptyScriptAuthor : "JMichaelTX"

(*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PURPOSE:
  • Returns a list of KM Variable Names that:
      • Start with specified Prefix
      • Have a value of "1"

AUTHOR:    JMichaelTX

REQUIRED KM VARIABLES:
  • Local__ItemPrefix -- the prefix of the variable names
  
REQUIRES:
  • KM 8.0.3+
  • macOS 10.11.6+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*)
property ptyKMValue : "1" -- required value of all KM Variables

set kmInst to system attribute "KMINSTANCE"

tell application "Keyboard Maestro Engine"
  set kmPrefix to getvariable "Local__ItemPrefix" instance kmInst
  
  set kmNameList to name of every variable whose name starts with kmPrefix and value is ptyKMValue
end tell

set AppleScript's text item delimiters to linefeed
return kmNameList as text

Here's the complete macro:

Example Output

MACRO:   Get List of Items Checked on Prompt

Version Date of Release
1.0 2017-10-12

DOWNLOAD:

Get List of Items Checked on Prompt.kmmacros (11 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


image

5 Likes

Hey @JMichaelTX - how do I modify your applescript so it returns the values in the order they were clicked? I have used this for multiple values and it returns them out of the order in which I clicked them. I think it is trying to order them alphabetically?

Hey Liam,

Keyboard Maestro has no means to detect the order in which checkboxes are clicked.

-Chris

@ccstone Hi Chris - thanks heaps for replying! Does this mean that the applescript wont be able to retain the items I have selected in the order I have selected them, when it passes them on to the next action?

That's correct.