Very sorry for this late reply @ccstone
Using your method leaves the user hanging in the Keyboard Maestro Engine and does not return them to the app they were working in.
That's a good point + thanks for the fix.
One problem though: DF 5.x has a problem when the Finder is the frontmost application. It locks up the entire Open/Save window and you have to
esc from it.
It has something to do with AppleScript and AppleEvents running on the main event loop.
From Jon (DF author):
I think the issue is that the Finder can't respond to Default Folder X's queries and run the file dialog at the same time.
AppleScript is implemented with AppleEvents, and AppleEvents are processed by an application's main event loop. There's only one main event loop in an app, and the AppleScript handling isn't reentrant, so it'll just lock if AppleScript is called externally while an AppleScript is already executing (which is essentially what's happening).
It was his suggestion to use
tell application "Keyboard Maestro Engine". But he couldn't have foreseen what you pointed out.
Given all of this, I'm kinda chasing my tail.
Here are the outcomes via each method:
- If you use
tell application (path to frontmost application as text) within:
- Finder = Broken (because of DF and/or AppleScript/AppleEvents)
- Any other app = OK
If you use
tell application "Keyboard Maestro Engine" within:
- Finder = OK
- Any other app = Focus is stuck inside
Keyboard Maestro Engine.
In my case, I've only been calling this from the Finder. So I could live with #2. But that wouldn't be good for this plugin or manually in a custom macro.
My first thought, as a workaround, would be to:
- Use Method #2 but replicate the "path to frontmost application" logic directly in the plugin or macro (not via AS).
- Then use that to switch focus back to the original app at the end of the plugin/macro.