Open/Save dialogs, macros, and Default Folder X

This is pretty esoteric, but might help anyone writing macros that interact with Open/Save dialogs in an automated manner.

I recently ran into an issue with a user who simply could not get MacroBackerUpper (MBU) to run—it would start, but fail to save the backup to the right location, or not save it at all.

After some troubleshooting, we tracked it down to his use of Default Folder X (DFX). This very useful utility puts a "wrapper" around Open/Save dialogs which enables a bunch of added functionality.

But that wrapper takes some time to draw (even on a fastish Mac), and that threw off the timing in the MBU export routine: MBU uses the File > Export > Export All Macros as Folder menu item. Once that's open, it inserts the correct name for the backup, pauses briefly, and then sends Shift-Command-G to open the "Go to folder" window and specify the destination.

But because of DFX, that command was getting eaten as it was trying to execute before the window was ready, so backups would either save in the wrong spot, or not save at all, depending on how many actions got eaten.

You might think I could use an "until buttons exist" action to get around that, but it doesn't work. The problem is that the base export window appears quite rapidly, so the buttons in it (Cancel, Save, New Folder) do exist, even though the window isn't ready for use.

And it seems the buttons in the DFX overlay aren't visible to Keyboard Maestro, so I can't try to detect them. So what was the solution? I downloaded the DFX trial, and discovered that it has very good AppleScript support. So I was able to add this at the start of my macro:

And then, once the backup completes, I use this bit to reactivate DFX:

As most backups take only a few seconds (processing can take quite a bit longer), DFX users will only be without their add-on for a short period of time—during which their Mac will be running a backup anyway.

So thanks, St. Clair Software, for the very nice AppleScript support!

-rob.

5 Likes