User Input, Checkbox, default value from variable

Hi,

Curious if there is a way to have the user prompt display with a checkbox that gets it’s on / off status from a variable? That is, if variable “Full” is 1, then the prompt would display a checkbox already checked with the variable name to the right of the checkbox.

Does that make sense?

Thanks

Of course. This:

…will produce this:


_[demo] Prompt with Preset Checkbox.kmmacros (2.3 KB)

For more info see this Wiki article.
‌‌

If you choose Help from the gear icon menu of an action (in this case the User Prompt action) you’ll be taken directly to the relevant Wiki article:

1 Like

Great help, thanks Tom. Looking at it now it makes perfect sense that this is how it would work. Now that I can do this I wrote a quick AppleScript to convert variables with a 1 into 1|0 and variables with a 0 into 0|1 and then ran the input prompt as intended.

You don’t need to do that, you can var %Variable%MyVar%|0|1

Keyboard Maestro uses the first entry as the default/selected entry (hence uses the 0 or 1 from the variable to set the initial value), and is smart enough to see that even though there are three values, they are all 0 or 1, so it is still a checkbox.

2 Likes

Brilliant. This is what I was hoping for. Thanks so much Peter

Hello @Tom, thank you very much for the posted macro :ok_hand: Since I'm not a KM nerd, I have a question about the "set variable..."

You use here for the first 0|1 and the second 1|0. If I continue this with 2|0 and 3|0, these are selected directly when calling.
However, if I mark them all with 0|1, then I can call up and activate/deactivate them all.

It works so well for me :+1:

My question now is whether my settings are correct or whether it just happens to work for me? If I did something wrong, you could help me out?

Enclosed my macro...

08)Everyone copy.kmmacros (8,6 KB)

1|0 simply means ‘checkbox selected’, 0|1 means ‘checkbox not selected’. (By default.)

I don’t know what 2|0 and 3|0 should do. The KM Wiki article doesn’t mention it. But maybe I’m missing something or this is something new. (If this is not something new then I guess that 2|0 or 3|0 works just like 1|0)

Not sure if I understand. Also when they are set to 1|0 you should be able to select/deselect the checkboxes. The 1|0 or 0|1 just sets the state of the checkbox when the prompt comes up. Once you actually select/deselect a checkbox the new value (0 or 1) is used.

1 Like

Thank you for your quick answer. It was my mistake of thought that I meant...
1|0 = Icons
2|0 = Desktop
3|0 = Night Shift
etc.
would have something to do with the number/arrangement (numbering) of the checkboxes and would not be marked or unchecked. Just as the variables are numbered consecutively.

For me it was/is important that the input window opens and no checkbox is checked. I did, yes, I did, even though unconsciously. Thank you very much again.

By choosing the format n|n (where n is either ‘0’ or ‘1’) you are telling the prompt that the input field should be a Checkbox Input Field (and not a text input field etc.).

Then, by either putting 1 or 0 on the first position you tell the prompt what the default state of that Checkbox should be (0|1: off; 1|0: on).

1 Like

Thank you again for your explanation. As a beginner I am very grateful for every understanding and explanation in this forum.

2 Likes

Yep, don’t hesitate to ask in the forum. Plenty of helpful people here. Also the KM Wiki (which has improved significantly over the last years) provides a lot of useful information. I’m also looking up things on the Wiki frequently.

4 Likes

Seriously! Even the last ~12 months have shown huge improvement in readbility and cross referencing.

3 Likes

I think this is mainly thanks to the work of @JMichaelTX, @peternlewis, @ccstone. And, of course, many of the improvements to the Wiki originate from (or are inspired by) questions and contributions by many forum members.

4 Likes

Ehm, sorry, just read your post again (sometimes I’m a bit slow). What you probably wanted to do —I think— is constructing a popup button (not a check box). Like this:

You can do this with this:

[example] Popup Button.kmmacros (3.0 KB)


You can also differentiate between the displayed value and the “real” value by prepending the real value to the displayed value, separated by 2 underscores:

Thank you for the information on the pop-up button :ok_hand:
I expressed myself wrongly from my side. I assumed that I would have to continue the enumeration for further checkboxes, as shown on the ScreenShot...

Now I know that this is underexposed for the function of the checkboxes. Thanks to your help, I'm now aware of the behavior of 0|1 and 1|0.

Can I use your macro for a YouTube tutorial? Of course I would link your contribution as a source in my tutorial.

1 Like

Ah, OK, I got now what you meant.

Of course, yes.

2 Likes