I am curious to hear thoughts on pros and cons.
As documented in my other postings about workflow for file handling, I have created some scripts that I am now using to format filenames and folder names. As I have been using them to clean up my files and folders, they have proven extremely useful at creating uniformity in my naming scheme.
Right now, I have implemented them as Python scripts that do the major part of the work, basically by taking in a file or folder name and figuring out the “correct” file or folder name to emit based on my underlying scheme. I have them created a series of KM macros, each of which looks at the current file(s) selected in Finder and applies the scripts to each item, with some additional KM action blocks that support the running of the script. There are right now 5 macros, and it set up so I can trigger a KM palette from which I select the appropriate macro to be run. This has proven very efficient.
The additional parts of KM basically related to a) looping through the Finder selection, b) checking depending on which macro it is to ensure the selected item is a folder vs file (eg don’t process a folder in the macro that renames files), and c) using a bash script that takes the supplied file or folder name, feeds it into the Python script that does the formatting, and then doing the necessary rename. Fairly simply bash scripts.
However, I often find that I have selected a bunch of files or folder and it is natural when working at my desktop with my Logitech mouse to just right click rather than jumping to the keyboard to trigger the KM palette and select the proper item, so it occurs to me that it would also be a good idea to encapsulate these operations into Finder services (or whatever they are called now under Mojave) as well.
It would be easy enough to create de-novo services in Automator and have them run the same embedded bash script. However, I don’t like that sort of duplication. The whole point of creating Python scripts as standalone scripts rather than embedding the logic in the KM macros is to isolate that logic, so it can be used in multiple places without code duplication, thus avoiding the issue of keeping the same script in two locations (Automater and KM, for example) in sync. By having a separate script file, I can make changes to that and the results are automatically available to any wrapper that uses it.
Therefore, it also makes sense to implement the full functionality in one place and then wrapper it for use elsewhere. So I can either create an Automator action that just calls the KM macro via AppleScript, OR I can embed the bash script in an Automator action (which itself calls the external Python script) and have KM execute that Automator action. Again, only one code base to be changed when something needs fixing or modification.
I am curious to know what others think is the more efficient solution, or a the better solution for whatever reason.
Right now, for this purpose, I am strongly leaning towards keeping the macros in KM as is (since they are already finished and working anyway), and have the Automator scripts call the KM macros. My major motivation for that approach is that KM macros are synced between all of my computers through Dropbox, while services do not sync between different computers, and so keeping functionality in KM when that is feasible and recreating the Automator actions/services on each machine seems less difficult and error prone compared to having to recreate a more complex Automator action on each machine.
Thoughts?