If Then Else Check boxes

What I would like to do is have a list of checkboxes and if the box is checked it will add that text to the tags on my blog,
If it is not checked it will not add that particular tag.
This works perfectly if I don't change the check boxes, but if I uncheck any one of them, to not include it, then it will add the 1st two tags that are always included and then post the entry.

Hi Steve,

Are these checkbox choices meant to be different from these two tags that are always inserted regardless of whether the boxes are checked or not?

If not, it seems like you should be able to resolve this issue by disabling or deleting these Insert Text options, so that only the checkbox options are reflected. If they are meant to be different, and you always want to include these first two tags while also having the option to include or not include the additional choices based on their checked status, it seems like what you have should already be working.

If the two checkbox choices are meant to be different from the current "Insert Text" tag 1 and tag 2, and the current macro isn't working as you expect even though it seems like it should be, please try

A) uploading the full macro (though the image helps, it's unfortunately not always enough to be able to see what's going wrong or attempt a fix)
B) posting the kind of output you want to be getting, and what the macro is actually producing.

1 Like

The two Insert Text Tag #1 and #2 are supposed to be different from the check box choices and are supposed to always be included.

So for example, if the number entered for Dat__Days is 0 and I uncheck Choice 1 then the resulting output should be...

"#Tag #1, #Tag #2, #Choice 2, #12/16/17"

What is happening is I am getting "#Tag #1, #Tag #2, submission" inserted and then it submits the post to the blog.

I have no idea where the "submission" is coming from.

Keyboard Maestro Actions.kmactions (6.5 KB)

Your macro works just like it's supposed to when I try it, so I can only guess that something else on your system is interfering and causing "submission" to be entered (perhaps a text expansion snippet from another app, or some other kind of autocomplete function in Chrome?) The only idea I can offer is to try inserting the various tags and choices by pasting instead of typing, as it's possible the insertion by typing is what's inadvertently triggering whatever's causing "submission" to be entered. Here's a tweaked version of your macro set to do that, along with a couple of other changes made to reduce redundant steps, like leaving the "otherwise" section in the If Then Else actions blank rather than inserting nothing via typing, and pasting the date variable directly instead of setting the variable first:

If Then Else Check Boxes.kmmacros (7.0 KB)

1 Like

Thanks, that is working much better.
I had tried pasting the text rather than typing it and I was still having issues with it before, but now it seems to be fine.
Also, I had tried the “otherwise” section the way you have it and it didn’t seem to make a difference.

The only issue I have with using the paste is that it wipes out something that I have saved in the clipboard that I need to use in other sections of another Macro.

I know that there are other clipboards that can be used, but I’m not really sure on how to use them.

For example: “Blog Name” is copied from a Google page and then it will be entered in as a tag as well as part of a URL on 2 other Google pages that are open.

Shot in the dark here, but stating the obvious: if any of the text insertions contain a carriage return in them, that might trigger a web form submission.

1 Like

No, they don’t.
They just have Tabs after each one to separate each tag.

Two things were happening.
First, it was adding the word submission as a tag and secondly, it was actually submitting the post, but they seem to be gone with what you sent me.

That’s solved easily enough. Just set whatever it is you copy to a variable right after you copy it and use the variable instead of pasting the clipboard. You could also just use KM’s clipboard history switcher to look through previous copied data and paste it manually that way if it doesn’t need to be part of the macro.

I think I got it mostly worked out.

I can't figure out how to do what you are talking about here...
"Just set whatever it is you copy to a variable right after you copy it and use the variable instead of pasting the clipboard."

The information that I want to keep is what is copied in this Macro that we worked on last week (or the week before)

It is what is copied in the very beginning and saved in the variable DAT__Search for 1) Clipboard.
It would be pasted right before the

This is the Macro we worked on last week.

Here's what I meant by "Just set whatever it is you copy to a variable right after you copy it and use the variable instead of pasting the clipboard.":

The name of the variable used here can be anything you like; the key point is that we can use the %SystemClipboard% token to essentially save the contents of the clipboard after a copy operation has been performed. You can then paste that variable later on in the macro, or in a different macro altogether, like this:

If you want it pasted before the date time variable, you could even combine both variables into a single paste action:

One more point I feel I should clear up: you said

With the way this macro is set up now, this isn't technically correct. The "Clipboard" option in DAT__Search for is currently being used as a placeholder to indicate that you would like to use the current clipboard contents, but it doesn't actually contain those contents itself. There are ways to have DAT__Search for display and save the clipboard's contents, but doing so would require some reworking of the rest of the macro, so I won't get into that unless you ask.

tl;dr: In your first macro, add a "Set Variable to text" action after the "Copy" action that uses the %SystemClipboard% token to save the clipboard to a variable after you copy it. Then, in your second macro, use an "Insert Text by pasting" action that pastes that same variable at the point where you were pasting the clipboard directly before (make sure the current "Paste" action is either deleted or disabled, otherwise it will re-paste the current clipboard as well as the "saved" clipboard variable).

Thanks for the help again.
I don't think I want to get into reworking it right now unless I need to in order to resolve this one last anomaly that I'm having right now.

When I leave everything as the default or turn any or all of Choice 1 - 5 or Choice 15 off "Choice 14" will insert itself into the body of the post and not as a tag.

When I turn "Choice 8" on "Choice 8" and "Choice 14" will insert themselves into the body of the post and not as a tag.

When I turn "Choice 11" on "Choice 11" and "Choice 14" will insert themselves into the body of the post and not as a tag.

I've tried recreating the conditional statements that were having the problem.
That didn't change anything.

I've tried recreating the conditional statements before the ones that were having the problem.
And that didn't change anything.

I've tried everything I can think of.

Keyboard Maestro Actions.kmactions (22 KB)

You're welcome. Unfortunately, I don't know which blogging engine you're using, and even if I did, I can't exactly access your editor to test your macro for myself to see why some choices are getting inserted into the body. Fortunately, I do have an idea for a more elegant solution that should sidestep the issue altogether: assemble all of the tags that you want to paste in Keyboard Maestro itself, then paste them all at once in a single paste operation. Here's a new version of the macro that does that, complete with annotations explaining how it works:

If Then Else Check Boxes 1.1.kmmacros (21.2 KB)

Not only should this version be more robust, it also lets you add, remove, or edit choices freely without needing to change a corresponding If Then Else action.

What you created works they way that you have in mind, but for this blog it doesn't work.
As you can see when I did it my way each tag get entered in separately with the # in front of it so it is searchable.

The way you did it it is one big tag.

The "Tab" is what makes each item separate and searchable.
A comma will also enter each tag separatly and make them searchable.

The other thing I noticed is that on Choice 5 there is actually and if then choice where if the checkbox if it is checked the tag is Option 1 and if it is unchecked it is Option 2 and that 2nd Option doesn't happen.

I don't know if the way the Tab Placeholder makes a difference or not.

I know that you wouldn't have access to my account, but I sent you a private message that tells you what the blog is if that helps any.

That definitely helped. Now that I know what blog engine you're using, I was able to test the macro myself and make sure it worked as intended. The key was going back to inserting text by typing, but doing so with the entire block of text assembled in KM, and making sure the typing didn't happen too quickly by making use of the technique outlined in this recent post. I also re-incorporated the branching options for Choice 5 depending on whether it was checked or not. Try this and see if this doesn't do the trick:

If Then Else Check Boxes 1.2.kmmacros (26.7 KB)

That is pretty much it, but the options for choice 5 still don’t work.
When It is checked it will give me Option 1, but when it is unchecked I get nothing.
It acts like any of the others that are unchecked.

Ah, I see where it went wrong. I was only testing for Tag__ variables that had a value of 1, so it was never seeing Choice 5 when it was unchecked. I changed that to only check the Tag__ variables' values for 1 after the initial check to see if a given variable is prefixed with Tag__ or not, so now it should work as intended.

If Then Else Check Boxes 1.2.1.kmmacros (27.4 KB)

Thanks again Gabe.
That looks like it did it,


Sorry, I spoke too soon.
When I change the Choices back to what they actually should be, the correct thing is typing out, but so is "Choice 1, Choice 2 and so on.
The “Choices” that are getting entered in are the ones that are on by default or checked.

And the actual entries are not being entered in, in the order that they appear in the list.
It seems as if they are going in alphabetical order.
This is not that big of a deal as long as 4 of them come up last, which they seem to do.

The "Choice 1" entries are because you still have variables called "Tag__Choice 1" "Tag__Choice 2" etc. with a value of 1 left over from this test version. You can either delete them directly from the Variables pane in KM's preferences or run this macro:

Tag__ Cleanup.kmmacros (3.8 KB)

and this problem should go away. Don't worry about deleting your new correct "Tag__" variables; they'll be recreated the next time you run the macro.

As for getting entered in alphabetical order, that is indeed what is happening, since that is how KM processes all of its variables when iterating through them in a For Each action. If you want to ensure that the tags/choices are always entered in the same order as your list, probably the easiest way to do so would be to replace the For Each action that checks all the variables automatically with individual If Then Else actions for every choice, like the way you had it set up before, only this time with the same Set Variable to text action that we use in the new version. In other words, instead of this for every choice:

you'd want this:

Of course, if alphabetical order is okay for the tags, then the current 1.2.1 macro should work fine once you've deleted the "Tag__" variables you no longer need.