I'm trying to refactor a macro so that it uses a subroutine. Then I can reuse that subroutine. Unfortunately the documentation for subroutine https://wiki.keyboardmaestro.com/Subroutines doesn't mention anything. (A side note, IMO not having examples in the wiki severely limits the utility of the wiki for a new user)
I've searched through here and the answers are way above my current skill level. Can somebody give me a simple example of the code for a subroutine (e.g. executing a shell script) where the calling macro has passed several parameters into the subroutine)?
Here's a totally contrived example that lets you input a shell command name, options for that command, and a folder path. The subroutine then runs the command with the specified options for the specified folder, and feeds the result through wc to return a count of lines in the output. That value is then returned to the main macro.
As I said, it's totally contrived and you'd get meaningless results (or an error) if you fed it a command that didn't generate line-oriented output and accept a folder path as input. But it demonstrates sending multiple variables to the subroutine, as well as returning a value from a subroutine.
Here's an example. I'm not really sure what kind of example you are looking for. This macro is a subroutine which will execute a shell script, passing the names of two files as local variables, and then returning the results. If this isn't what you want, give me more information and I can try again.
Subroutine: Find Difference between two files Macro (v11.0.3)
OK, however I view forum answers as potentially being less reliable than a similar answer in the wiki. Anybody can answer in the forum. A poor or incorrect suggestion may be picked up, but it may also not be. A similar example in the wiki is far more likely to be corrected.
I did search the forum before asking, and that was the reason for requesting a simple example. I found several very comprehensive responses that were way too complex for a new user: e.g. being examples using AppleScript etc.
Keyboard Maestro looks like a very good product and is obviously loved by its users. I've bought a licence as proof of my belief in its value. However, the learning curve is very steep. I come from a software engineering background, and I view the documentation (wiki, tutorials) as seen from the perspective of a new user as being inadequate. As it stands, the wiki is merely an incomplete reference manual. The product has been around for some time, so I'm surprised so little effort has been expended on improving the documentation.