Having finally secured a bit of free time, I'm going to go about rejigging and reorganizing my KBM macros, which have become somewhat chaotic as I've developed my familiarity (by making experiments) with macro-building. I'd love some tips or resources as to how to best organize my macros, although I think I'll go with a mostly app-specific organization alongside aliases that fit into process or workspace palettes. Granted, there are many helpful resources already available on this forum regarding both the above and hotkey specifications.
One question I did have that I can't find thoroughly addressed in any of the current discussions is whether there is any consensus regarding scripts in KBM. Specifically, is it better to have the scripts embedded within the macro or have the macro run a file at a given path? I've generally done the former, however this means that I usually have to copy and paste the script (whether Apple, Java, Shell, Python, or whatever) into the appropriate text/script editor in order to make substantial changes. For this reason, as well as to version any possible future changes through something like GitHub, I'm considering whether I should take all of the scripts out of their macro and just run them from a folder that allows for easier editing and versioning. Would there be any drawbacks to this or, more generally, how do other people with growing macro libraries full of scripts go about this?
IMO, that is the best approach:
Compiled scripts (.scpt) will run faster because they do not have to be first compiled by KM.
Keeping all of these scripts in a designated KM Scripts folder provides for much better script management and testing
It is much easier to test/debug a script, open in Script Debugger 7, but run from a KM Macro.
Allows you to quickly find scripts using macOS tools like Spotlight, especially when you use file tags.
Allows you to take advantage of other systems like DropBox, GitHub, etc
The only drawback I know of is that when you want to share a KM Macro, you either have to also provide the script file, or copy the script into the KM Execute Script Action.
AFAIK, there is no official KM documentation on using script text vs a script file, but hopefully @peternlewis and @ccstone will jump in here to clarify.
I have a Script Library in which I keep most of my reusable script handlers. So for KM Macros for my own use, I make use of the use <Script Library> command to access these handlers from my scripts. I have a KM Macro which aids in the search, selection, and insertion of a call to a handler in this Library. It can also copy the handler directly into the target script, if I need to share that script without sharing my Script Library.
I have no idea which is faster when, and what might affect them. I expect it could change over time and depend on file caching and such. For example, if Keyboard Maestro has the text of the script, it writes it to disk and then executes the script that is written, but that written file will almost certainly be cached in memory and quite possibly never touch the disk at all.
.scpt files will store properties from the script, which is the most obvious practical difference. Text filed and text in Keyboard Maestro will not.
As always, if performance is important then the only real way to determine which is faster in your specific case is to test it.
For myself, I've never had any reason to move text scripts in Keyboard Maestro to a file, though I have lots of scripts (usually perl scripts) on disk that Keyboard Maestro might execute - but the choice is made for reasons other than performance. The difference in speed is unlikely to be of interest unless you are executing the script thousands (probably many thousands) of times.
For those who use the built-in Time Machine for backups, note that running scripts in Keyboard Maestro from a file will cause Time Machine to backup the files anew each time it backs up. While script files aren't usually large, this may cumulatively affect a user's amount of available backup space while potentially making it more difficult to locate past versions in Time Machine backups as there will be more instances of the script to consider for recovery.
Those aren't likely to be significant effects, but they've led me in many cases to keep script files as easily referenced copies but I execute them in Keyboard Maestro by embedding them within macros.