MACRO: MacroBackerUpper—it's like Time Machine for your macro library

Hey @griffman,

Just wanted to provide an update and some observations on these great macros.

Feature Request:

  • If Keyboard Maestro is hidden when the macro starts, rehide it after the macros are exported.
    • I did this on my personal copy, but when I download updates I have to do it again; having it incorporated into the official release would be nice.
  • Only show the final report if manually triggered
    • Otherwise just a Notification Center notification if ran from idle/periodic/time of day trigger etc.

Bug Report: shell scripts status 1 errors
The following shell scripts return A LOT of Task failed with status 1 errors...

Action Screenshot from macro: tasks | 06 Analyze modified groups (click to expand/collapse)

Action Screenshot from macro: 06 Analyze modified groups (click to expand/collapse)

Action Screenshot from macro: 06 Analyze modified groups (click to expand/collapse)

Bug Report: broken execute a macro action

There is a missing execute a macro action in the following macro: upd | Update check (click to expand/collapse)

I haven’t had time to look into your last DM about the AppleScript but I’ll try and brainstorm something this evening.

Thanks again for a great macro system!

-Chris

1 Like

I think these are great ideas. If I could add my feature requests/things I intend to look into on my own:

  • Run periodically without user input (other than the option to cancel like during "Present countdown timer for settings access" prompt)
    • My use would be to run this periodically from an always-on mac, provided the user has not moved the mouse recently ("is afk") and/or the KMsync file has not changed recently.

Thanks again @griffman, I really love it.

I'll work on the feature list, as for the periodic option, it's how I have mine set. However, I don't like distributing macros that automatically run on a periodic basis; it somehow feels "wrong" to me to put something on someone's Mac that runs without their saying "yes please run this."

I do show a couple options in the help for users who want to add automatic usage—periodic or idle—for those who may not be familiar with those triggers.

-rob.

That’s a good point. I’ll have to go read the documentation a little more thoroughly. I guess I just need a way to disable the final dialogue, but to be fair, I have not looked to see if such a thing is included yet. I only just tried it this morning. Thanks again

It's not, but it will be in the next release.

-rob.

1 Like

I'm 99% certain these are unavoidable, due to the way diff works. This tripped me up in the past, and drdrang was able to figure out what was going on:

The answer lies in how diff works. When diff finds a difference between the two files, its exit code is 1. Nonzero exit codes typically indicate an error, so when Keyboard Maestro sees that exit code, it bails out. If you look through the Engine.log file, you'll see something like Task failed with status 1 which is true but not very helpful if you don't know diff's exit codes.

The workaround is to click on the gear icon in the upper left corner of your Execute Shell Script action and change the settings on "Failure Aborts Macro" and "Notify on Failure" from ✓ to ×. That should get you the output you expect.

So that's what I have to do whenever I use diff (and a couple other commands, as it turns out). But I don't know of any way to block the log entries for these things that aren't really errors.

-rob.

1 Like

Hi, @griffman. Thanks so much for your responsivenss to the issues that have been discovered during the roll-out of MBU! Considering the amazing functionality of MBU, it seems that the issues have been relatively minor. (Are you getting any sleep now? :sleeping:)

Coincidentally, I'm working on a macro (named: Engine.log Tool) that has some functionality that you might consider if/when implementing the above MBU enhancements.

Engine.log Tool that has three modes, one via direct trigger and two via calling macros that use the Execute a Macro action.

When Engine.log Tool is run via direct trigger (Mode 1) it displays a Prompt For User Input dialog with seven buttons.

For one of the buttons (Reduce) there are sub-options that are presented using a Prompt With List. (Coincidentally there are seven sub-options.)

When two of the five sub-options are selected, the macro does its respective task and then reports results.

For the other five sub-options, additional information is required and obtained via Prompt For User Input dialogs (customized to the particular sub-option). Like with the other two sub-options, the five sub-options complete a task and report results.

(This might sound complicated, but the macro is easier to use than to describe. :grinning:)

With Modes 2 and 3, the information that would normally be supplied by the Mode 1 user responses (dialog+PWL or dialog+PWL+dialog) is supplied by the callers via the With Parameter. The only difference between these modes is that Mode 2 reports results and Mode 3 runs silently.

For example, one of the sub-options is delete. For Mode 2, the caller supplies delete in the With Parameter. For Mode 3, the caller supplies 0:delete in the With Parameter.

Engine.log Tool includes this simple set of actions to determine the mode of operation...

If Then Else.kmactions (2.3 KB)

Version 1.2 is out now, with two Chris-requested features and some bug fixes :).

New feature #1 is the ability to control when (or if) the final onscreen summary dialog appears. You can set it to Always, Never, or Only if macro manually triggered. If you select the last option, you'll only see the dialog if you run MBU via its keyboard shortcut or directly from the KM editor.

New feature #2 is that MBU now tries to clean up the house before it leaves: It checks and saves the condition of the Keyboard Maestro app (running and visible, running and not visible, or not running), then restores that condition when the backup is done. So if you run MBU on a timer, you'll see KM open when it starts, but then (hopefully) also see it quit when the backup is done.

I also fixed a bug (thanks Chris!) in the update routine that was causing it to fail. So you won't be able to use the update manager this time, as it'll break. (If you want to fix it, just take out the call to launch the missing macro in the Update check macro.)

-rob.

3 Likes

I must be tired because I can't really tell what your macro does from reading :). I assume it's some sort of log manager that lets you easily find and remove entries from the log?

-rob.

1 Like

Hi, @griffman. The information I supplied was simply to describe how you might handle various modes of operation. But obviously my description missed the mark. I’ll send you the macro via PM so you can see my comments in context. I’m not quite ready to release it in the forum.

Ha, I totally missed that! See, I am tired!

-rob.

1 Like

Every time I try to run MBU I get the following... A backup folder is created in $HOME with my KM macros but it hangs at the "administration" dialog (and obviously doesn't move the folder to its designated destination). When I first ran it I did have some identically named macros, but I've consolidated those now. I've also tried to reinstall / re-run having first deleted all the 'rg_' variables.

2023-11-12 10:42:23 Execute a Shell Script failed with script error: Runtime error near line 16: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 17: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 18: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 19: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 20: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 21: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 22: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 23: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 24: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 25: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 26: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 27: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 28: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 29: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 30: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 31: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 32: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 33: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 34: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 35: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 36: UNIQUE constraint failed: groups_new.Group_ID (19)
Runtime error near line 37: UNIQUE constraint failed: groups_new.Group_ID (19) in macro “•main | MacroBackerUpper” (while executing Create/update the database).
2023-11-12 10:42:23 Execute macro “subs | 94 Control export window” from trigger Execute Macro
2023-11-12 10:42:28 Action 15365556 failed: Split Path failed because with path %Variable%rg_MBU_tNewestBackup%
2023-11-12 10:42:28 Split Path failed because with path %Variable%rg_MBU_tNewestBackup%. Macro “•main | MacroBackerUpper” cancelled (while executing Split Path “%Variable%rg_MBU_tNewestBackup%”).

I just added some troubleshooting steps to the help page, but this problem occurs when MBU didn't finish properly, leaving the database in a weird state. The easy fix:

  1. Delete the latest backup.
  2. Delete the zDatabase.db file in the zSupport Files - Do not delete folder at the top level of the backups folder.
  3. Re-run MBU.

You shouldn't need to delete either of the global variables, though, unless the path is wrong in rg_MBU_BackupLoc.

Please let me know if this works. I'm also working on some logic to recover/notify if such an issue is found on launch.

-rob.

Hi Rob, thanks for your help! Sadly that didn't address it. I deleted the 'KM Backups' folder entirely (including the zSupport Files folder), and deleted the rg_ variables for good measure, then re-ran accepting the defaults (i.e. 'KM Backups' into ~/Documents). Same issue, hanging on the 'variable-setting administrativia' popup.

Can you look in the log and let me know if there's an error message? Alternatively, if the macro is still running (menu bar icon spinning), select Start Debugging from the menu bar icon and let me know which command it's working on.

thanks;
-rob.

Now I'm getting these messages:

2023-11-12 15:32:34 Execute macro “•main | MacroBackerUpper” from trigger Editor
2023-11-12 15:32:38 GetProcessForPID(2359) failed with -600 for <KBMRunningApplication “Keyboard Maestro” <0x60000002c8f0> pid=2359 bid=com.stairways.keyboardmaestro.editor Abht>, using cached version
2023-11-12 15:32:38 Action 15365916 failed: Manipulate Window could not find any matching windows
2023-11-12 15:32:39 Execute macro “subs | 94 Control export window” from trigger Execute Macro
2023-11-12 15:32:44 Action 15365556 failed: Split Path failed because with path %Variable%rg_MBU_tNewestBackup%
2023-11-12 15:32:44 Split Path failed because with path %Variable%rg_MBU_tNewestBackup%. Macro “•main | MacroBackerUpper” cancelled (while executing Split Path “%Variable%rg_MBU_tNewestBackup%”).

It's hanging on subs | 94. I also switched off and on KM's screen recording privileges in System Settings.

Ugh, this appears to be the -600 AppleScript error that's not related to the macro at all. I have some code in there that's supposed to help, but doesn't seem to be in your case.

As a test, select any macro, then use File > Export > Export as Folder. When that's done (you can delete the export), try the macro again.

-rob.

Sorry, no joy :frowning:

2023-11-12 16:01:51 Engine Starting 11.0.1
2023-11-12 16:01:59 Execute macro “•main | MacroBackerUpper” from trigger Editor
2023-11-12 16:02:02 GetProcessForPID(2694) failed with -600 for <KBMRunningApplication “Keyboard Maestro” <0x6000004ac420> pid=2694 bid=com.stairways.keyboardmaestro.editor Abht>, using cached version
2023-11-12 16:02:02 Action 15365916 failed: Manipulate Window could not find any matching windows
2023-11-12 16:02:03 Variable “KMVAR_instanceTheData” excluded from environment to ensure the environment is not too large
2023-11-12 16:02:04 Execute macro “subs | 94 Control export window” from trigger Execute Macro
2023-11-12 16:02:09 Action 15365556 failed: Split Path failed because with path %Variable%rg_MBU_tNewestBackup%
2023-11-12 16:02:09 Split Path failed because with path %Variable%rg_MBU_tNewestBackup%. Macro “•main | MacroBackerUpper” cancelled (while executing Split Path “%Variable%rg_MBU_tNewestBackup%”).

While I work on some more AppleScript code, does it work if you quit and relaunch the Keyboard Maestro engine?

-rob.

Sorry I left in the 'Engine Starting' comment above but didn't mention that that's exactly what I did. Also -- probably not relevant as I can see you're internationalising using the 'one true date format' (ISO 8601) but I'm in a GMT timezone.