I now only make KM macros with chatGPT

My experience using chatGPT to make Keyboard Maestro macros over the past 5 months has completely changed how I use KM. I am neither a KM guru, programming expert or chatGPT lover -- in fact, I struggle using all these tools. But I know enough to be able to check what's going on, and importantly, chatGPT can also help me do that. The problems I have been able to solve recently using chatGPT has made Keyboard Maestro even more valuable to me -- and that's why I'm posting this -- maybe it will help others.

To illustrate, I'm providing 2 examples: one simple and one complex (at least to me).

For this first example I instructed chatGPT to make a .kmmacros file to replace spelled numbers with arabic numerals in selected text. After it finished, it gave me a link to download the .kmmacros file and this summary for how the macro operates:

It operates on selected text and converts examples such as:

* `twenty-three` → `23`
* `one hundred and five` → `105`
* `two thousand and six` → `2,006`
* `three million two hundred thousand` → `3,200,000`
* `three and five` → `3 and 5`
* `minus twenty-five` → `-25`

It deliberately leaves **ordinals** (`twenty-first`) and **decimals expressed with “point”** (`three point five`) unchanged.

Double-clicking on the .kmmacros file opened it in KM and after reviewing it I enabled it and tested. The macro failed, so I pasted the KM error message into chatGPT along with a description of exactly how I tested and it described the problem, fixed it and provided a new .kmmacros file to download. That one worked perfectly.

Simple example: Replace Spelled Numbers with Numerals
Replace Spelled Numbers with Numerals.kmmacros (35.7 KB)

In my experience, chatGPT tends to use Execute Script and Apple Script actions to do the heavy lifting. When I have specifically instructed it to use native KM actions wherever possible, it has sometimes asked me to provide a sample .kmmacros file with the desired type of KM actions. And I often will have it explain to me how both KM actions and particular parts of the scripts work. To me, that's really helpful for learning.

To explain my more complex example, here is the prompt it produces when I select 4 image/video files and trigger the macro:


The macro reduces all the image or video files to the new width and quality specified and optionally shows a report of how much space was saved for each file. Progress during long runs can be monitored by the name of the report .txt file which changes every minute showing how many MB have been processed. It also uses imageOptim to further reduce the image sizes.

reduce selected images or videos.kmmacros (31.5 KB)

This one required many iterations in order to correct errors in the .kmmacros files chatGPT produced and to add features that I wanted later. I also modify the macro myself, of course, when it's easy. Although it took a long time to make, it was simple because all I was doing was testing each chatGPT iteration and explaining what wasn't working. I can't imagine how long it would've taken me without chatGPT to make a macro with these features, if I could even do it.

I'm interested in what Keyboard Maestro experts out there will say about my experience -- I anticipate I'll be told to be very careful and check the code. Although I did so at first, I must admit to doing so less now that many months have passed with so many useful macros produced. I'm ready to be admonished.

5 Likes

Hardly an expert, so these opinions are worth what you're paying for them :wink:

  1. If a macro does what you want, does it matter how you made it or how it works?
  2. If using an LLM helps you make macros you couldn't (lack of knowledge) or wouldn't (lack of time) have made before -- brilliant!
  3. LLMs have been trained on a lot of shell script and JavaScript, some AppleScript, not a lot of KM-specific stuff and LLM-created macros will reflect that in both logic and "correctness"
  4. LLMs can produce working code/macros, but they rarely produce good code/macros. That doesn't really matter (see point 1) unless you also want efficiency -- obvious example of that is where the LLM includes and AppleScript or Swift script which would be fine for a single execution, then puts that inside a "For Each" Action so you get instantiation/compilation delays every... single.. time... you... loop...

IMO, the sweet spot is to use LLMs to fill in the gaps in your knowledge and save some time -- and use some of that saved time to increase your knowledge so you can improve your macros. A virtuous circle, and it'll get easier as you learn the foibles of your LLM. An example of that is with AppleScript -- being trained on many non-AS patterns, LLMs have a habit of forcing case on a string before doing a text comparison, not knowing that AS text comparisons are case-insensitive by default.

A more concrete example? In your second macro, the first Action after the initial comments sets a variable, Local_baseNames, to an empty string. But Local variables don't exist until they get set to a value! So you're wasting a millisecond creating a variable to delete it. Similarly with setting Local__NewWidth and Local__CRF to hard-coded values immediately before setting them via the "Prompt" -- why?

You'll see more of both of those in the future, so watch out for them. Every millisecond helps! :wink:

1 Like

Thank you @Nige_S for the tips. I realize that LLM's don't have true intelligence, but I wonder if I explained details like you mentioned it would be able to learn that for the future?

I don't know for sure, but my guess is it would because I have told it my preference for how I want several things done and it seems to be remembering. For example, I have told it to always prefer the simplest possible solution, provide a lot of details about exactly what it did and to just give me the facts and don't waste words being nice to me.

I use the most advanced model that I can and keep notes on what I learn in my large "notes on keyboard maestro" Google doc

That's beyond me -- my main interaction with the various LLMs is sorting out the problems they've caused for other people!

If you haven't seen it already, have a read of the "A coding agent skill..." thread -- I'm sure you'll get some ideas from that.

Yes, that was interesting, but I think most there are above my Keyboard Maestro skill level. For example, I barely have a clue how to write bash or Apple scripts and so avoid them.

On the other hand, I really have made an effort to learn both so I do scroll through to see if it generally makes sense. Since chatGPT uses them so much, I ask questions about code within them that is mysterious to me.

Also, I tell chatGPT to make it maintainable by breaking scripts into smaller chunks with variables that I can display for debugging.

2 Likes

The most optimistic construction that one can put on all the time that people are spending in this way is the Iain McGilchrist image of "The Master and his Emissary" – the thought that the properly human is the world of imagination and value – the rest can be delegated.

Master-slave relationships are, however, notoriously ambiguous and reversible – Roman literature in particular expresses deep unease about the dangers of this kind of relationship.


What is more, Master and Emissary competes poorly with a rival image – that of addictive goods, first distributed free, or at low cost, to establish dependency, before prices are ramped up to gouge.

B.A.T. dumping cart-loads of free cigarettes in East Asian villages before the second world war to establish profitable dependency, others dumping cart-loads of free brandy in Southern African villages, as a prelude to breaking up rural barter economies with a need for brandy-buying cash, to create a source of labour for mines. See Charles van Onselen – RANDLORDS AND ROTGUT, 1886-1903

If the startling scale of investment in LLMs is ever to break a return, or avoid breaking the markets, then prices will need, in time, to gouge very painfully, once dependence has set in.

If you do use these tools while they still don't break the bank, then use them to actively learn – not to sit losing your time, training their models, becoming dependent, in exchange for baubles and trinkets.

2 Likes

@ComplexPoint

I appreciate that you quoted my exact words, but the parts you omitted are a significant counterpoint to your post:

Although it took a long time to make, it was simple because all I was doing was testing each chatGPT iteration and explaining what wasn't working

In other words, the way I'm using chatGPT with Keyboard Maestro is so simple that it allows me to do more macros or more advanced macros than I would have done otherwise -- this preserves my energies for tasks that truly require my efforts.

On the other hand, I think your points are interesting and relevant to something I did recently: made a request to receive all my chatGPT posts. In one chat session it said it could organize all those to make an easily searchable archive -- that will be useful if I reach the point where a Declaration is needed:

"When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among..."

Note the founding fathers didn't say "another person"... how wise they were

Simple here means little cognitive effort ? And this is a good thing ?

I wish I could share your optimism :slight_smile:

The healthy market in gym memberships, and equipment, does suggests quite broad awareness of the lamentable costs of minimal physical effort.

But perhaps the costs of declining cognitive effort have yet to be fully noticed ?

AI’s impact on cognitive ability: MIT study reveals more troubling data — MIT Media Lab

Good luck !

More practically, I would suggest that this forum can understand you better, and give you faster and more solid solutions, than any model of language, however large.

To those who help you, you will have contributed a gym exercise.

They, in return, can do a better job, than any LLM, of helping you to learn and build your own capacity to flex such muscles, and solve such problems.

Again, you quote what I wrote, but I omit the key parts:

This is what tools have always done when used properly.

1 Like

And one of the things that tools have always done is, of course, to amputate the faculties that they extend.

My personal feeling is that the cost is greater when those faculties are cognitive.

But bottom line – this forum will reward your time more richly than interactions with an LLM which makes you wait, under-occupied, while it learns from you.

As much as I've gained and enjoyed most of my interactions in this forum, I can honestly say that I've learned at least 10 times more using ChatGPT.

As for the time spent, I have to wait much longer, even to the point of forgetting what I asked sometimes, when I post questions on this forum. And because I cannot instantly correct any misunderstanding like I can with ChatGPT, that waiting time is further amplified each time I have to interact with someone over and over again who has misunderstood.

By contrast with ChatGPT, every time I have to wait the short time that it takes to see a response I'm able to do other productive things and never forget what I asked because I get the answer so quickly.

Again, I want to emphasize that I really appreciate most of the interactions that I've had on this forum. But there have also been a lot that have been quite a waste of time. I don't think that's ever happened with ChatGPT regarding keyboard Maestro help.

1 Like

I’m using Claude to aid in my creation of KM macros. Is AI making us stupid? I can’t answer for that, but I recall in the 1970s when people said cheap electronic calculators would make us all stupid. I don’t think it happened. AI is not my Lord and savior. It is just another tool in my toolbox.

Calculators probably did amputate some arithmetic capacity – I’ve seen people reach for them to evaluate surprising things – but arithmetic is a small part of life.

The cognitive amputations are much more general and widely reported now.

1 Like

I rely on Claude for quite a bit of stuff with Keyboard Maestro, but I use it to handle those things that either can't be done with native Keyboard Maestro commands, or that are completely beyond my skill level.

When you give an AI the entire macro, you will wind up with what you have: A functional macro that, in essence, is usually just a series of calls to execute various scripts. This is good in that you get a functional macro, but the downside is that debugging it will require using AI.

As an example, I rewrote your "more complex" example using as many native Keyboard Maestro actions as I could. The sips and ffmpeg bits remain, because that's the best way to get those things done.

But instead of having just a few gargantuan scripts that run everything, my macro has only three small scripts that do the actual conversion. The error trapping, logging, and progress tracking are all handled by Keyboard Maestro. There's no need to write to a file to track progress, because an onscreen indicator shows you what's happening.

And because the error trapping is done independently for each type of conversion, it's simple to make different errors do different things. (The same thing is possible in your script, but you'd have to edit the shell script code to change behaviors. In this version, you just add new Keyboard Maestro actions where needed.)

Whoa, somehow that published without my clicking the button…we do have three kittens in the house!

Anyway, here's the report my version generates:

This version is probably marginally slower than yours, because I use Keyboard Maestro's loops instead of doing a batch conversion in a shell. That means I have to start a new shell for each command. However, that time is quite small compared to the processing time of converting each file, so it doesn't really hurt much in the end.

Here's the macro if you want to take a look at how it works:

Revised image-video resizer.kmmacros (53 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 26.6.1
  • Keyboard Maestro v11.1.1

It was a fun exercise, working through how to replace the scripts in your macro with native actions in mine. One thing you might want to teach your AI is about the mdls command, which can more-easily get the image dimensions for movies or stills than the AI's various methods.

-rob.

@griffman glad you had fun with it. I made some test files (.mp4, .jpg, .HEIC), and ran first my version (which worked fine) and then yours, which unfortunately failed with the message: "ERROR: Could not optimize test1.jpg with imgOptim" so I couldn't complete the comparison. I also tried .jpeg and got the same result.

The key point here is that you obviously have more Keyboard Maestro expertise and can see all these issues. For example, you say " you might want to teach your AI is about the mdls command" which is the sort of thing which I probably never would come up with -- unless I visited this forum, of course.

This is a very important point and I mentioned this in a response to @Nige_S

I tell chatGPT to make it maintainable by breaking scripts into smaller chunks with variables that I can display for debugging.

My post was aimed at helping those, like me, who are not Keyboard Maestro experts. We appreciated the power of Keyboard Maestro but the learning curve is so steep that we can barely scratch the surface of what it can do. If used right, chatGPT provides a way to scratch deeper.

I appreciate all the time you spent on this and your helpful comments (and those of Nige_S, etc...)

Please stop conflating "Keyboard Maestro expertise" with shell-scripting ability and knowledge about built-in and third-party utilities.

It's not that difficult to "get good" with KM -- break your problem into small, sequential, steps and then look at the Wiki to find the Actions, Tokens and Functions to implement those steps. The hardest part is the problem solving and mapping your own terms for things to Keyboard Maestro's, both of which only really come with practice.

That level of KM ability will cover 90% of the macros you write, and you'll be able to create macros both faster and better than you will by prompting an LLM to do so.

Is it worth the time and effort to get to that stage? I'd say yes, because the largest part of that is developing a "programmer's mind-set" -- the ability to define then deconstruct a problem, solve each part in turn, then combine those parts into a complete solution. Skills that are applicable to way more of life's journey than just the "making KM macros" part.

Then you've got the "script" parts of your macros, where you're calling out to utilities like ffmpeg, sips, mdls, executing JavaScript in a browser window, and so on. Scripting is an order of magnitude more difficult than macroing, scripts tend to be more "bespoke" than KM Actions, and LLMs are much better at writing them -- so it definitely makes sense to ask for their help with those.

But remember that script-based solutions are vastly over-represented on the Forum. That's the nature of this place -- people ask for help when they can't do something with "native" KM Actions, and often those things can't be done (at least, not reliably/easily/quickly) without going "outside" to the shell, AS, or JXA.

Did riding horses or driving cars cause our legs to atrophy away? My guess is that chairs are more dangerous than cars where leg vitality and mobility are concerned. Do we give up calculators to maintain our math prowess?

For balance, I recognize the vast harm done by cars, and computers by both their use the infrastructure that supports them. But like guns, the tools are not the problem. Using them for good or ill is the choice we continually make. Lay responsibility the only place it can show up and that is with us.

@BernSh Couldn't have said it better. You're obviously a radical, wedded to old-fashioned notions like responsibility, choice, maturity, ...

@Nige_S But users like me wouldn't even know they are over-represented. I hesitate to seem critical because I really do appreciate how much help I've received from you, but I fear you share a common problem experts have: they lose sight of what it's like to be a novice.

As a teacher, I taught an unusual variety of subjects, ranging from language and math to elementary school students to physics, biology and chemistry to college science majors. Almost none of them ever intended to become experts in the subject I was teaching, but instead needed to learn it for another goal.

That's how it is with Keyboard Maestro -- almost no one uses it because they want to become a programming expert -- they just want to use it for another goal. As novices they stare at the screen wondering how they are supposed to know what to call the action they need, or the "Keyboard Maestro" way of doing things, much less the worlds of scripting, ffmpeg, etc...

I've written code in over a dozen programming languages in order to solve research problems, teaching-related tasks or other highly technical things that needed to get done. I didn't want to learn any of them, but I learned enough so I could get the job done. Despite decades of experience like that and being considered extremely educated and analytical, I struggled tremendously to learn Keyboard Maestro.

I tried over and over to learn it, even taking courses and gave up several times because I just couldn't figure it out. Even now, I still feel I'm not that good at it. I would even say my experience with Keyboard Maestro has been unique among the programming related experiences I've had where spending the amount of time I have put me into the "power user" category.

THAT'S why I tried to "give back" to my fellow Keyboard Maestro strugglers when I made this post. As I said in my first paragraph, "maybe it will help others"