This seems to work, however, if I have Mail highlighted and then bring up spotlight search using β-Spacebar and start typing any of my replacement keys, they get caught by keyboard maestro because it seems to think Mail is still the active window.
How do I get KM to ignore keystrokes entered into spotlight search? (Is this a rule to add to my macro group?
For some reason, my Archive Mail macro seems to require "This string is typed" whereas the rest of my gmail -> apple mail macros work with "This hot key". For example my previous simply maps p to up arrow
Is it obvious why my Archive key only seems to work with "This string is typed" and not a normal hotkey?
I searched through the Macro Library and did not see an existing library focused on this "transition from gmail to Apple Mail" problem. Has anyone else made this transition / created a library to do this that is already better / more complete?
Background
I'm looking to move my email out of gmail and gsuite accounts into the coming Apple mail to get my communications away from Google's all seeing eye.
Iβm guessing you know all the angles on this but just to tap on some possibilities:
There is no way to detect Spotlight search is activated? Maybe MacOs hides this info?
Is this a well known limitation of KM? Not trying to be snarky here, it just jumped out at me right away because I use spotlight a fair amount. (Mostly to launch a handful of common apps I should look to use KM hotkeys instead)
Are there other ways to devise the key mapping Iβm after that might get me to the solution?
For example, interrupt command-space to check if Mail is active window, if so hide it and the show spotlight search?
tell application "System Events"
tell application process "Spotlight"
if (get name of windows) contains "Spotlight" then
return true
else
return false
end if
end tell
end tell
But this gets incredibly cumbersome.
When I use single keystroke HotKeys I use a palette to display them and remind me they're active.
I can toggle this on/off at need.
Keep in mind that you're gaming the (macOS) system, and that always comes with limitations.
It can also be done by examining the output of the ps command. If the cpu column>0, that means the window is active. This can be put into a KM shell script action and tested.
There is a small amount lag compared to not doing these checks. (Perhaps this is what you meant by cumbersome?) I have a pretty fast mini, and I can deal with the lag, but curious if there are any obvious ways to make the macro more efficient?
This is perhaps more of a Mail question, however, In threaded conversations, if a given email in a thread is selected as indicated with a blue highlight (shown below) there does not seem to be a way to determine this state.
In this state, an Option-arrow key is used to move between emails. So if this state can be determined, I'd want my keys to use the option modifier. Any ideas on how to figure this out?
Related, and still more Mail oriented, I do not see an obvious way to return focus to the main inboxes pane of the window. Normally, I'd expect ESC to do this. Not sure why Mail doesn't support this, any ideas on how to use KM to do this?
Thanks for this, did you mean top ? Would this be more performant than the AS suggested by cm?
It's amazing that it could detect the Spotlight search window.
How about "Alfred"?
I changed Spotlight into Alfred and it does not work.
Edit: Turns out I made a mistake. There were two places to change and I changed only one place. It's working great now!
From this post, an answer provided by Chris as well.
Code for Alfred:
tell application "System Events"
tell application process "Alfred"
if (get name of windows) contains "Alfred" then
return true
else
return false
end if
end tell
end tell
I found a mistake in my archive macro and that was the only lagging one. I think it is pretty good now.
I did find that the Help menu search input still captures these unmodified keys. Is there a way to detect for Help -> search input active so I can allow the character to be typed the same as the spotlight?
The reason I would go to this trouble is that I think many people will migrate away from gmail and gsuite when Apple debuts their new mail hosting service next year. This is my goal, to host my mail using my domain with Apple instead of Google.
It would be nice to make this as clean as possible so I can share it in the macros forum.
edit: I had planned to have N and P do next and previous and archive, but that doesn't make as much sense in Mail as it did in gmail.
If you use the "inbox zero" goal of archiving "complete" email, the default Mail behavior of "search based on unmodified key entry" is unwanted.
As a result, I have re-enabled N and P to do next and previous, which duplicate the behavior of J and K which are the actual default next and previous gmail hotkeys. (mirroring vim)
Alfred is a background-only app, so it is never seen as the frontmost app by the system regardless of whether its UI is frontmost or not.
I don't think it sends a notification event when its UI is activated, so apps like Keyboard Maestro can't notice.
LaunchBar is similar, and I was furious when it became background-only β because it limited my ability to use Typinator, FastScripts, and Keyboard Maestro with it.
I changed it to β+β§+Space in Alfred, and then let KM to trigger it (see macro below).
The purpose of this change is to keep the original Alfred trigger so that I don't have to adapt to new trigger.
Then I can ask KM to disable some macros or macro groups.
The only thing is that I need to manually enable them afterwards. That's not a problem, because I've been using a hotkey to toggle enable/disable before.
It saves me from the first three unnecessary steps: 1. typing search strings in Alfred interfered by the keyboard mapping macros (set in KM) β 2. disable the macros/macro groups β 3. back to Alfred to type β 4. enable the disabled macros/macro groups.
A second thought:
If someone tends to use the Alfred trigger to close the Alfred search window, then the Alfred running detection might still be useful, because if the hotkey is used to close the search window, then there is no reason to disable those macros/macro groups. We might even want to enable them.
But there's a kludgey workaround β check for the number of selected messages. This will work only if the selected item is the root level of the thread β and it won't bump you off the end of the thread.
tell application "Mail"
tell (some message viewer whose index is 1)
set numberOfSelectedMessages to length of (get selected messages)
end tell
end tell
return numberOfSelectedMessages
I have βJ bound to an AppleScript that moves focus into the message list and then activates the Down-Arrow.
If the first number is 0, then Spotlight is not the front window. I tested it a dozen times and it was 100% reliable. There's a 50% chance it's reliable 100% of the time with further testing. I can't speak to the accuracy of the AppleScript since I'm daft at AppleScript but deft at shell. But the AppleScript code looks like it could be 100% accurate in this case.
Usually AppleScript has the most reliable solutions. If alternate solutions are ever banned on this forum, I'll be a lot more quiet. But sometimes it's fun to see an alternate solution. I was even tempted to show you a solution with Find Image, but I knew there would be better solutions than that.