[KM] Put Selected Actions into Group Action

###MACRO: [KM] Put Selected Actions into Group Action
####EDIT: ~~~~~ VER: 1.1.1 2016-05-05 ~~~~~

####DOWNLOAD:
[KM] Put Selected Actions into Group Action.kmmacros (11 KB)

See Peter's original macro at:

Peter, many thanks for this excellent macro.

I have modified it a bit to:

  1. Create the Named Clipboard ("KM Group Action") if it does not exist
  2. Fix an issue which did not put the Group at the end of the macro when the Actions were all at the end of the macro.

Author: @PeterNLewis (Ver 1.0)
Mods by: @JMichaelTX (Ver 1.1)

PURPOSE: Move Selected KM Actions into a new Group Action

HOW TO USE:
(1) Select the KM Actions to move
(2) Run this macro
(3) IF the "KM Group Action" Named Clipboard does NOT EXIST,
user will be prompted to select a Group Action to use
and it will be used to create the Named Clipboard

REQUIRES:
(1) Keyboard Maestro Ver 7.1.1+
(2) Yosemite (10.10.5)+

2 Likes

Thanks for this. It’s going to be quite helpful.

There’s probably a bug in it, because it did something weird the first time I tried it, but then it worked OK after that. Here’s the steps I did, to the best of my recollection:

Ran the macro, it told me to select a group action, so I stopped the macro.

Ran it again and selected a group action this time and clicked continue, and it told me it created the named clipboard, etc. Did not group my actions this time (that’s OK).

Ran it again, and it nested 3 groups inside themselves, without my actions.

Did some undos, tried it again, and it worked fine.

I love development work, don’t you? :slight_smile:

That was probably the problem.
Notice in the Alert I say to

By stopping the macro you caused it to fail. :smile:

Silly me. I guess in the future when someone says “and press continue”, I shouldn’t be surprised if it doesn’t do what they say it will, huh? :open_mouth: LOL.

Perhaps the message was too easy to overlook.

I have modified the Alert to make it more explicit, and posted the update to Ver 1.1.1 in my OP above.

AH! You were serious! Thought you were kidding.

I wish we had an Alert that only had an OK button. I’ve wished for it several times.

We do - use the Prompt For User Input action.

I thought about that later. I should probably update the macro to use the Prompt.

Well, now I just feel stupid. :smirk: Of course. Duh.

Thanks!

If I select the top action in a macro and execute this macro, the Group ends up underneath the next action. Like this:

Is there a way to adapt this for Repeat, If Then Else, etc.? I’ve tried to kludge my way through it but have failed so far.

It works with all those things. What issues are you having?

I’d like to have a similar function that places the selected actions into a Repeat Action, or into an If Then Else Action, or a For Each, etc. I’m still trying to get it working myself but am having little success.

Yeah, that’s not going to be easy, because, as I’m sure you’ve found out, you can’t just paste in the Repeat action (for example) then paste in the actions that were cut. They won’t paste in the right place.

Do you happen to know JavaScript? If you do, I could give you some ideas of how to do it. I’d write it for you, but it’s not something I’d use since it’s fairly trivial to do it manually, and I’m focused on other things right now.

Yes I’ve seen. I’ve been trying to use keystrokes to position the cursor for pasting the actions back in, but there are too many variables about what other actions may be placed around the Repeat to do so automatically and reliably.

I don’t know any JS, but as you’ve noted it’s not a big enough issue to worry over and further. Usually when I’m planning actions that will repeat or be If/Then/Else’d, I know ahead of time :slight_smile:

Thanks!

1 Like

It’s possible @JMichaelTX could figure it out, and I’ll let him respond to that. :slight_smile:

This works for me:

Manually

  1. Copy the Repeat Action to a Named Clipboard, I'll call "KM Repeat Action"

Select the Actions to Move

In Your Macro to Move Actions to Repeat Action

This is the same as my macro at the top post of this topic,
EXCEPT:

  1. Uses a different Named Clipboard for "Repeat Action"

  1. ADD 3 TAB Keystrokes after paste of Repeat:

You should be able to copy my macro, rename the copy, and make these changes.

1 Like

Use it all the time :joy:. One suggestion: After the group is created immediately select Rename from the Gear menu — it is always what I do after executing this macro, and is harmless in any case.

Please feel free to post your version of the Macro that adds this feature.

Ah, no fair making me do some work :wink: Should be straightforward. I’ll get back to you.