Using AppleScript to Enable a Macro Group and Then Show It's Palette

Howdy folks, I am running into an issue that seems like should be straightforward but I am unable to get it to work. Basically I want to use AppleScript to enable certain macro groups according to which client I am working with on the phone.

Initially I would run this AppleScript at the beginning of my workday as part of my initial work flow and then all client macro groups would be enabled, and any time I needed to open a palette they would appear right away.

More recently I wanted to use AppleScript to enable each macro groups only when I am on a call with that specific client instad of having them all enabled throughout my entire workday. So I added an AppleScript to enable each clients macro group and placed it just before the action to open their palette(s) but the palettes do not open unless I run the macro a second time (once the macro groups have already been enabled).

I have tried adding a pause between the AppleScript that enables the macro group and the show palette function, as much as 2 seconds but it just doesn’t work. Is there something I’m doing wrong or any reason why a palette is not available to show immediately after the macro group has been enabled?

Attached is a screenshot of the troublesome part of the macro. Thanks for any help you can provide.

1 Like

Two points to consider here:

  1. Do not use enable/disable. Use Activate/Deactivate Macro Group action.
    • This will process much faster
    • Only affects the Mac the macro is running on, whereas enable/disable will cause the KM Sync file to update and cause other Macs that use this sync to change.
  2. Use the above KM Action rather than AppleScript

Here you say "activates" but above you say "enables". which is it?
If you make the suggested changes above I suspect it will fix this problem.
If not, please upload your macro file and image. If you continue to use the script, you will also need to upload it.

See How to upload your macro. Instructions for uploading to an existing post are just below the main instruction.
You may also find this Macro useful: MACRO: Upload KM Macro to New or Existing Topic @KM [Pub]

1 Like

So I tried that but it doesn’t actually disable the macros in said macro groups. What I would like is to have those macros completely disabled so as to not accidentally trigger them.

Sorry, meant to say enable; not activate. I'll edit my original post to show the correct terminology.

But regardless, activating/deactivating the macro group doesn’t prevent the macros inside from triggering from what I can tell (unless I'm doing something wrong still).

I didn't post the entire macro because portions of it contain confidential info. But I copied the relevant portion into a new macro and used the one you linked to to upload it here. Awesome macro you made btw! Attached is also the AppleScript I used to enable the macro groups.

tell application "Keyboard Maestro"
set enabled of macro group "Notes - LB DHS General" to true
set enabled of macro group "Notes - LB DHS-ICE" to true
set enabled of macro group "Notes - LB DHS-USCIS Country: Colombia" to true
set enabled of macro group "Notes - LB DHS-USCIS Country: Cuba" to true
set enabled of macro group "Notes - LB DHS-USCIS Country: Ecuador" to true
set enabled of macro group "Notes - LB DHS-USCIS Country: El Salvador" to true
set enabled of macro group "Notes - LB DHS-USCIS Country: Guatemala" to true
set enabled of macro group "Notes - LB DHS-USCIS Country: Honduras" to true
set enabled of macro group "Notes - LB DHS-USCIS Country: Mexico" to true
set enabled of macro group "Notes - LB DHS-USCIS Country: Nicaragua" to true
set enabled of macro group "Notes - LB DHS-USCIS Country: Venezuela" to true
set enabled of macro group "Notes - LB DHS-USCIS Forms" to true
end tell

MACRO:   Open Macro Groups (for testing)

DOWNLOAD Macro File:

Open Macro Groups (for testing).kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


No need to actually "disable" every macro.
When the Macro Group is "deactivated", it is NOT possible for any of its Macros to be triggered.
See Macro Activation .

Wrong. See my above comments.

Instead of a script that enables each macro, just do this:

  1. Deactivate all Macro Groups whose Macros you do NOT want to be triggered
  2. Show Macro Group and Show Palette for desired MG

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

Example Output

image

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Demo How to Activate and Deactivate Macro Groups and Palettes [Example]

-~~~ VER: 1.0    2021-05-10 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Demo How to Activate and Deactivate Macro Groups and Palettes [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


@cdthomer,

BTW, I would create a "sub-macro" that deactivates all of the Macro Groups.
Then Call that sub-macro:

  1. at the start of each day.
  2. At the beginning of each macro that activates a specific Group.
  3. When you are done with the MG activated in #2.

I like what you're trying to do. It seems like a good contribution to "contextual computing". I might steal it - as I, too, have multiple customers on the go in the same timeframe.

Thank you for your continuing help! I made a test macro that would deactivate a specific macro group. However, I was still able to trigger macros from inside it even though it was supposed to be deactivated. I get the feeling it may have to do with the macro group's settings, because I have them set to "Always activated" as can be seen in the screenshot. Does it need to be set to something else for the activate/deactivate action to work properly?

EDIT: Never mind, I adjusted those settings (setting it to Activated/deactivated when) and it works great! The thing I did like about enabling and disabling however was the visual effect of the groups being grayed out which allowed me to quickly see which ones were enabled/disabled. I have about 30 different clients, so a lot of different groups and it can be helpful to see very quickly if the right ones are enabled or not. Is there some way to mimic this with activation/deactivation?

Edit 2: I just now noticed that while this works for the most part, if I switch out of Notes to another app that these macro groups are not available in, when I go back to Notes the palettes do not reappear even though the macros themselves are still activated and able to be triggered. Any idea why the palettes only appear initially and then do not reappear if I leave and come back to Notes?

EDIT 3: Well I seem to have figured that out too though I'm not certain why it works this way. When the macro groups were set to "Always activated" the palettes would appear initially upon triggering the "Show palette" action. But as I mentioned, when switching out of Notes they would disappear (which is normal as I have them set to only show up in Notes), but then not reappear when switching back to Notes which is how they worked before. But now changing the macro groups' settings to "Shows/hides a palette when" they now appear when I use the activate macro group action and reappear whenever I switch back into Notes until I deactivate them. Seems strange but it's working like I want so I'm just gonna roll with it.

Thanks again for your help, you always come through for me even though I'm certain my questions are quite rookie in nature :laughing: