How to Return String Values From Actions :-)

Wow. That opens my eyes a lot. The three second delay happens all over the editor, not just there. Can you help with the more general problem? I just tested if disabling the engine removes that delay. Apparently not. My main problem with the editor are these three second delays that happen constantly as I'm editing actions. Roughly 50% of the time I spend in the Editor is just waiting for the hourglass to disappear when I look at the screen, and then waiting for my typing on screen to catch up with my fingers. It seems that the delay is only created if I pause my typing for about 1 second. My guess is that the editor does not call the engine to recompile as long as I'm typing without a pause. But that doesn't add up since shutting down the engine doesn't seem to reduce the delays. I really don't know what's causing these delays. If you can fix this problem I will be indebted to you forever. I can use KM all day, but it's time for me to get some food.

Hey @Sleepy,

It's hard to say for certain, but you do have a lot of groups and macros.

On my system I have:

Macro Groups: 152
Total Macros: 1874

Enabled Groups: 105
Enabled Macros: 405

I haven't verified these figures, but they should be correct.

Here's how I counted them (run in the Script Editor):

# Count Enabled Macro Groups and Enabled Macros
tell application "Keyboard Maestro"
   set mGroups to (get macro groups whose enabled is true)
   set enabledMacroCount to 0
   repeat with i in mGroups
      set enabledMacroCount to enabledMacroCount + (count of (get macros of i whose enabled is true))
   end repeat
   set AppleScript's text item delimiters to linefeed
   return {"Enabled Groups: " & (count of mGroups), "Enabled Macros: " & enabledMacroCount} as text
end tell


Well, then maybe I need to export all the macros I don't use often in order to get the Editor to be more responsive. I'll check into how easy that is to do with many hundreds of macros and groups. The truth is most of my macros I use for a few months then stop using them, I keep them around only to help me research how I solved a problem before. But if they are slowing me down, I can probably just copy them into some Apple Notes folders for reference purposes. I notice that if I click on the EDIT button in the KM editor the macros are more accommodating as lines of text for saving into Notes. It would be cool if the editor let me import macros that were exported this way. It looks like all the information is there.

I suppose a quicker test would be to use a different Mac. The problem is my older Macs have even MORE macros because every time I buy a new Mac I just rewrite all my macros out of my head and that is a natural kind of cleanup. I love rewriting my macros because I usually make them better each time around.


Only Local or Instance variables that are in an existing macro are included in the list. So they should not “linger around permanently … even if the macro that contained them is long gone”

This would only work until the macro was deleted.

I have no plans to implement this.

I have no idea what would cause that. The only thing the editor does is save the macros. That can take a long time if your macro file is extremely large (which generally happens only if you have a lot of macros with very large amounts of data in them, such as inline images). Check your Keyboard Maestro Macros.plist file and see how large it is.

I tried to duplicate this memory leak. If I toggle a macro group off and on multiple times, I can see the apparent memory use in Activity Monitor grow. However if I actually look at the heap I cannot find anything in there that is growing - at least not anything I have any control over. So currently I don't have any suggestions as far as the memory usage goes.

Note that an increasing number in Activity Monitor does not necessarily mean very much. If the memory is lost to the application it will eventually migrate on to disk and become irrelevant to actual memory use.

I stand corrected! Sorry if I inadvertently cast aspersions where they weren't warranted; as I said earlier, I understand why KM populates the Insert Variable list with local and instance variables and appreciate that it does so. I did think that local and instance variables stuck around even after any macros containing them were deleted, especially since @CJK said they do for him as well, but I admit I didn't test this, and I'm happy to take your word for it.

If they do, that is a bug. They did not in my testing.

It took me 5 minutes of searching this site to find where the Macros.plist file was. Then it took me 5 minutes to figure out why my ~/Library folder didn't seem to exist on my Mac. It's probably "hidden" by default in the macOS GUI, but I found it. You asked me for the size and it's 72 MB. I have no idea if that's big or not. I tried to open the file to see it but it said I needed additional Xcode components and I wasn't sure I should click on that so I declined. Should I accept and view the file?

I'm sure you are right that virtual memory does not necessarily mean that macOS will get bogged down, but I can tell you that around 5 GB my computer grinds down to a frustrating level and around 8 GB lots of important features of macOS stop working properly. Like the "Force Quit Applications" window which takes minutes to pop up. So this increase in memory is a functional problem. I even had one time where I couldn't do anything but press the power off button, and I waited a long time.

If I take my car to the dealer to fix a squeak, and there's no squeak, they say they can't fix it. At least here you've heard the squeaking, so I don't feel too guilty. And you've got a copy of the car in your shop so I'm perfectly content.

For reference, my Keyboard Maestro Macros.plist is 1.1MB. I have 159 macros. Scaling proportionally, I would estimate you to have 11,450 macros.

For further reference, I have 873 and my macro plist file is 2.1MB.

I do have a lot but I don't think I have that much. SO something may be wrong in that file. Should I try to read its contents? How would I reset it?

Yes, that is large. Every change in the editor is made by writing the entire file. So you are basically saving a 72Meg file for every change.

Mine is about 1.5MB and I have about 1500 macros.

Probably you have one or more macros with a large image (or maybe large styled text) in it. Note that custom images pasted in to icons could also count here, although any icons generated by Keyboard Maestro or from the icon chooser will not count for much.

Realistically, the design for all this was appropriate for a few hundred macros, and it works reasonable with a few thousand, but if you start getting way past that or start having large amounts of data stored in macros, then it is going to bog down. Maybe one day I will rewrite it to use a database of some sort, but that will have its own problems (like database corruption for example, which is rarely a problem with Keyboard Maestro since each write is the entire data).

There is no easy way to determine which macro is large, probably the easiest way is export your macro groups (perhaps in sets) and see which ones produce a large export file - the export file will be comparable in size to the size taking up in the Macros plist file.

I downloaded the Xcode components required to view the plist file. That took 15 minutes. I've opened the file. It's some sort of tree data structure. But I don't know what this structure means. I see a folder at the top called MacroGroups. I'm starting to decode what I see, but now I notice Peter's new post so I'll stop writing this post and study his interesting response.

Yes, everything you said makes sense. I'm not sure what the 72MB is caused by, but I do use FindImage a lot so I'm guessing I have an excess of image data in there. I think for me the quickest option is to find some older folders that I'm not using and see if I can export and delete entire folders. I didn't know you can do that in "sets". But I need to figure this out.

Currently, Find Image pretty much has to have the image in the action, although the images tend to be relatively small, they can add up.

In Keyboard Maestro 9, you can have the image stored elsewhere, in a file or a Named Clipboard, either of which would remove it from the macros file per se.

1 Like

Yes most of my Find Image images are small, like the ones I use in my OCR utilities to convert bitmapped letters in screen images back to text, but it never occurred to me that size matters, so it's likely I have some large ones that are using a fair chunk of my 72 MB. I'm trying to do searches (for "screen"?) right now in the Editor to see if I can find the main culprits. But I live in a time zone where it's about time to go to bed so I'll have to try this another time.

A post was split to a new topic: Macro: Get Counts of Enabled and Disabled Macro Groups and Macros

Chris @ccstone et al:

I moved your post/macro to a new topic in the "Macro Library" section to make it easier for all Forum readers to find. It is a great macro that many will find useful.

Macro: Get Counts of Enabled and Disabled Macro Groups and Macros

1 Like

Oh, rats, you beat me by 54 macros. (I'm very competitive. I lost my first game of Snakes and Ladders as a child and cried inconsolably.)

I've reduced my Plist file from 72 MB down to 11 MB, at the same time I've reduced my number of macros from 1800 to 600. The KM Editor already feeling more responsive. But I will need to take another break and do some more testing later. I'm not sure if this will impact my experiences with memory leaks, but it has already made the Editor more responsive.

As Peter explained, it's better to not have to save 72 MB of data after every edit I make. I didn't realize that it was doing that. I guess it makes sense. I agree that a database would be more efficient but I can see why Peter might not want to do that. I can certainly adapt by cutting down on storage. I don't mind adapting. I just didn't know that was an issue for me. Maybe there should be a KM Editor Menu item that tells you how much disk space you are using and warn you that certain sizes will impact performance.

And I didn't say before, but I'm excited that Peter says there will be options next version for storing images in a different location. I'm not sure how this will work, but if it will also allow me to pass an image as a parameter to a function, that will thrill me. Right now I have to duplicate code whenever I want to perform some code on an image.