Help needed with very slow Keyboard Maestro pallet appearance...how to debug?

Hi all

in the last couple of weeks i have had severe performance issues with Keyboard Maestro. Specifically, the issues is with pallets. In takes anywhere between a 2-4 seconds delay between when i issue the hotkey and until the pallet appears.up until a few weeks ago this was instantaneous...

im using latest Keyboard Maestro and latest Catalina. On a new 2020 MBP 13" with 32GB of RAM.

This has caused Keyboard Maestro to become almost unusable...I would really appreciate any help from all of your experience and how to approach debugging this. Any help would be highly appreciated!!

thx so much in advance

Z

I used to have a kind-of similar issue when the palette had icons, and I had pasted in large icon graphics instead of resizing them down first. I thought this had been resolved, but perhaps not?

Hope this helps.

thx @DanThomas

yesterday i managed to allocate some time for deep debugging. Turns out the whole issue (at least it seems so) is caused by a cron macro i had running every 3 seconds:

still not clear why a cron macro would severely slow down KM but would love to hear any thoughts from @peternlewis and the community

best

Z

All those tokens you have listed in there are gotten via AppleScript to iTunes/Music. AppleScript is horrendously slow.

The macro running every 3 seconds wouldn't cause much of an issue, even writing a file every 3 seconds wouldn't cause an issue assuming it is an SSD (a spinning disk might have some issues with continuously writing small files, but unlikely).

But continuously accessing AppleScript or worse JavaScript via AppleScript can definitely cause a performance issue.

ahh i see, thx @peternlewis

is there any other way (maybe bash) that one can get music info to pipe to text that dosent kill the system?

best

Z

Sorry Peter, but I have to strongly disagree.
To get all of those iTunes track properties took only 0.01 sec when run from Script Debugger 7.

Here's the script:

tell application "iTunes"
  
  --set oTrack to track 1 of library playlist 1
  set oTrack to current track
  
  tell oTrack
    set trkName to name
    set trkArtist to artist
    set trkAlbum to album
    set trkRating to rating
  end tell
  
end tell
set OTID to text item delimiters
set text item delimiters to linefeed

return {trkName, trkArtist, trkAlbum, trkRating} as text

So maybe Z’s AppleScript or iTunes is gummed up.

It's easy to test, just replace the tokens with static text and see what changes as far as performance goes.

Maybe the issue is somewhere else.

Maybe the Mac just needs restarting because some part of the system interprocess communication is lagging.

Could be, but that is NOT what my testing shows.

Results of Using this script in a KM Macro:

use scripting additions
use framework "Foundation"

set gTimerStartDate to current application's NSDate's |date|()

tell application "iTunes"
  
  --set oTrack to track 1 of library playlist 1
  set oTrack to current track
  
  tell oTrack
    set trkName to name
    set trkArtist to artist
    set trkAlbum to album
    set trkRating to rating
  end tell
  
end tell

set scriptResults to trkName & " - " & trkArtist & " (" & trkAlbum & ")  " & trkRating
set elapTime to (round (-(gTimerStartDate's timeIntervalSinceNow())) * 1000) / 1000.0
set scriptResults to (elapTime as text) & tab & scriptResults

return scriptResults

Script Debugger
0.01 sec in SD timer
0.006 sec calculated using ASObjC
image

Script Geek
0.006 sec
image

KM
Macro Time: 0.32 sec
AppleScript Time: 0.06 sec

The AppleScript runs very fast (0.006) when run from either Script Debugger 7 or Script Geek.
But when run from KM the same AppleScript is 10X slower, taking 0.06 sec.
With the total time for the Macro at 7X slower, taking 0.32 sec.

Conclusion

So, Peter, this strongly points to the slowness being due to how KM is executing AppleScripts.

Here's the macro:

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

MACRO:   Log iTune Track Properties [Example]

-~~~ VER: 1.0    2020-08-27 ~~~
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:

Log iTune Track Properties [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


thx guys for the detailed responses!

just to clarify (again i am not very technical so maybe im still missing the point :smiley: ), but what i was issuing was using the built in Keyboard Maestro tokens (https://wiki.keyboardmaestro.com:8443/token/CurrentTrack) and writing them to a text file. I wasn't running any custom Applescripts:

image

Also: i i have rebooted many times over the past few weeks where i had severe slow downs (until i identified the problem) which didn’t help. Disabling the macro solved this.

i used linux for 15 years and had a similar cron/bash script that did the same with zero lag on the system.

thx again

Z

Here are my suggestions if you want to fix your macro:

  1. Use an Execute an AppleScript action with a modified version of my script.
  2. Instead of writing to a file every 3 sec, simply append a KM variable (as I do in my Macro), and then write to a file much less frequently (> 1hr)

I would expect that to eliminate most of the 2-3 delay you mentioned in your OP.

thx @JMichaelTX

appreciate the answer. i will try your script and let you know!

the problem is that in this case i need it to follow changed tracks to show the music info in the menu bar (im using texbar for that):

so every hour wouldn’t help much :slight_smile:

thx

Z