(note that to update a plug in action you must manually remove it from the ~/Library/Application Support/Keyboard Maestro/Keyboard Maestro Actions folder before re-installing it)
It doesn’t seem to auto-focus the “Choose Folder” window. That means you have to reach for the mouse (and click on the “Choose Folder” window to focus it) before you can get back to the keyboard. Which we all love . Even pressing the esc key, to exit the window, won’t work until it’s first focused.
It doesn’t work with Default Folder 5.x. IOW: The type of window that’s opened is not recognized by DF, and the DF window chrome and its other features are unavailable. The best of which is “Enable Finder Click” which allows you to change the current folder (in the Open/Save dialog) to Finder window you click on. That feature would match very well with this plugin.
Before finding this plugin (and all of its clever features), I had been using the following:
tell application "Keyboard Maestro Engine"
activate
set dir to POSIX path of (choose folder with prompt "Choose Folder")
--return the POSIX path of dir
end tell
I still use this though, because of the keyboard and DF issues above.
Using your method leaves the user hanging in the Keyboard Maestro Engine and does not return them to the app they were working in.
Ahh!
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.
set frontApp to (path to frontmost application as text)
if frontApp does not end with "Finder.app:" then
tell application frontApp
set dir to POSIX path of (choose folder with prompt "Choose Folder")
end tell
else
tell application "System Events"
activate
set dir to POSIX path of (choose folder with prompt "Choose Folder")
set frontmost of application process "Finder" to true
end tell
end if