Macro Group Active Only for a Specific User Account?

I would like to create a macro group which is active only for a specific user account. Is this possible? If not, what would be an easy if/then to check the user account?

The reason I want to do this is that I am using the Sync Macros feature to keep the same macro set across all of the computers in my home. But there are some macros my wife likes that I don't, and vice versa. I realize there is the "Disabled on this Mac" feature. However, each of us might log in to any of the computers. It's not a question of which computer is being used, but rather who is logging in to a given computer that determines whether or not I'd want a given group to be active.

Thanks for your consideration!

John Feinberg
Montclair, NJ

It’s easy to check the current user by using the KM tokens %UserLoginID% or %UserName%

Is there a way that an expression can be evaluated to enable/disable a Group? I could use this inside an if/then but I would prefer not to have to put an "if %UserLoginID%=jfeinberg" in lots of macros.

Not in the definition of the group, no.

But you can create a macro that's triggered on user login to have variations on this theme to thereby enable/disable a group:

KM 0 2021-12-15_14-40-31

Very nice - I'll give this a try!!

Let me know how you get on or if you have other questions.

OK I tried it! Just one minor problem... When this script runs, it disables (or enables) the group on ALL computers regardless of who is logged in.
Suppose I log on to an iMac as user scott. The Test group is enabled.
Suppose I then log into a MacBook as user jfeinberg. The Test group is disabled.

I then go back to my iMac. The test group is now disabled on that computer as well!

So - can I enable/disable a group on a per-logon basis rather than on all computers sharing the keyboard macro file?

Thanks,

John

Oh - I didn’t expect that but I think I know what’s causing it and you mentioned it in your first post: you use KM synch, so any change to your KM environment is reflected across all your Macs.

You can test this by manually disabling a macro group on one Mac and then checking to see if that’s been replicated on another Mac. I’m fairly sure this is the problem.

As far as I know, the only way to get this method to work is to turn off KM synching so each of the Macs is left with the latest versions of your macros/groups etc and then they’ll operate independently.

I don’t know what your setup is, really, so I don’t know how essential KM synching is. For example - are you frequently modifying and/or creating macros and so you need KM synch to propagate the changes across your Macs? If not then simply turn off KM synch and only turn it on temporarily when you want to change or create a macro. Otherwise, we’ll have to think of a different approach.

I’m not at my desk now until tomorrow, so if someone else doesn’t jump in with a suggestion in the meantime I’ll have another think and post something later.

I really love the KM Synch feature. I don't change the macros that often, but I have a LOT of computers (most of which are now running OpenCore so that I can run Catalina and later). So even though I don't make too many changes, I'd still be frequently turning the sync on and back off again. I definitely want to keep the synch feature on all the time.

Or you could just call a macro that validates and cancels if appropriate. Couldn't you? Just a thought.

OP said in post #3 that wanted to avoid doing that.

In post #3 the user said he wanted to avoid an IF statement. I simplified the problem a little bit by saying the IF statement could be replaced by a macro statement.

It still involves editing all the OP’s macros, but right now I don’t know what the alternative is.

Could this help... I'm pondering it... what if an asynchronous macro called this?

OP here - I think the thing to do may be to just put the if/then in those macros that are user-specific. There are only 5 or 10 of them so it's not so bad. I can make a shared code block so that if tweaks are needed I only have to change it once. It would be more elegant if I could have just one if/then for the group, but I want to keep kmsync turned on so that is not an option.

@feinberj, as @tiffle mentioned you can use the user-related tokens. Keyboard Maestro has a long list: Tokens [Keyboard Maestro Wiki]

By that, do you mean calling an external macro to do the work?

Hi @feinberj - I've done some more digging into the wiki and on this page manual:Macro Syncing [Keyboard Maestro Wiki] I noticed this:

"If there are some macros you do not want active on a Mac, you can configure any given Macro Group to be disabled on that particular Mac by turning on the Disabled on this Mac setting in that Macro Group."

As I don't have KM Synch turned on I wasn't sure what this meant and in fact my Test group definition looks like this:
KM 0 2021-12-15_22-57-02
However, after turning on sync it looks like this:
KM 1 2021-12-15_22-56-25

It's hard to miss the difference! "Disabled on this Mac" I think refers to syncing for that particular group on that particular Mac.

Checking that checkbox therefore, prevents the macros in this group from syncing anywhere else. That means, if you can identify the macros that you want to be unique to a specific user you can just put them in a group and disable syncing for that group. I then believe my original suggestion regarding a macro triggered at user login should work, as disabling/enabling such a macro group would not then sync across to the other macs.

I haven't tested this (it's way past my bedtime) but if you want to give it a go feel free!

Can I set "Disabled on this mac" inside a Keyboard Maestro macro, the same way I could disable a Group from inside a macro? If yes, then that would be a perfect solution!

There isn't a native KM action to do this, but you can do it in AppleScript. These examples set and unset the Disabled on this Mac property of the macro group called [Test] - you can use whatever group name you like or you can pass the contents of a KM variable to the AppleScript if you like...

tell application "Keyboard Maestro"
	set disabled on this Mac of macro group "[Test]" to true
end tell
tell application "Keyboard Maestro"
	set disabled on this Mac of macro group "[Test]" to false
end tell

I really am going to bed now. If you need help with the AppleScript or whatever let me know.

Cheers.

1 Like