Anyone know of a trick to make the Global Macro Palette (GMP) appear at the cursor?
Oddly, in preferences, you can toggle on that very feature for the Conflict Palette only, but not for any other KM palettes.
I'm asking because I have a Macro Group that nicely pops up at the cursor when I press a button on my Logitech MX3 mouse. To get to the KM's GMP, one item is a macro that just displays the GMP but I can't get it to be right at my cursor. (Two large monitors; trying to minimize cursor movement as much as possible.) Maybe there's some trick?
I guess the alternative is to just forget the GMP altogether and just use another Macro Group that has those macros, maybe? ...thanks...
There might be better ways of doing it, but this is something I just whipped up.
It uses Keyboard Maestro's %CurrentMouse% token to set two local variables, which are then used in an AppleScript to set the GMP to just below and right of the mouse.
It works well in my limited testing, but try it out and see if it works for you of if you have any issues.
That does work well and certainly qualifies as a trick in my book. Thanks so much.
Two issues, one I fixed and one needs additional assistance.
I adjusted the delay to 0.001 in your AS. That smoothed out the palette's final movement; pretty easy. But as you can see from the screen shot, the cursor arrow is a little bit off of the palette.
Ideally, I'd like an offset enough to have the cursor already on the first choice (since we're talking about tweaking this at this point) in the GMP's window.
So, is there a way to stick in an X,Y offset (one that I could play with once you show it to me )?
Glad it’s working for you! And your question is easily doable. I'm no longer at my computer to supply you with a full script but adjust the set its position line as follows:
set its position to {(mouseX - 10), (mouseY - 10)}
Basically that subtracts 10 right and below the mouse position. Adjust those numbers until the GMP appears with the mouse over the first selection.
Edit: since I’m on my phone that script might not be formatted correctly but you get the idea
Edit 2: I'm back at a computer... the numbers need to be larger, at least on my MacBook. Try this:
----------------------------------------------------------
# Author: Chris Thomerson
#
# Current Version: 1.0
# Version History: 1.0 (Initial script)
#
# Created: Wednesday, December 29, 2021
# Modified: Wednesday, December 29, 2021
# macOS: 11.6.2 (Big Sur)
#
# DISCLAIMER
# Permission to use, copy, modify, and/or distribute this
# software for any purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
----------------------------------------------------------
### Requires Keyboard Maestro 8.0.3+ ###
set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
set mouseX to getvariable "local_mouseX" instance kmInst
set mouseY to getvariable "local_mouseY" instance kmInst
end tell
tell application "System Events"
tell application process "Keyboard Maestro Engine"
repeat until window "Keyboard Maestro" exists
delay 1.001
end repeat
tell window "Keyboard Maestro"
set its position to {(mouseX - 50), (mouseY - 40)}
end tell
end tell
end tell
Yep, thanks. I was already playing with the numbers when you replied. Here's my tweak using your input:
set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
set mouseX to getvariable "local_mouseX" instance kmInst
set mouseY to getvariable "local_mouseY" instance kmInst
end tell
tell application "System Events"
tell application process "Keyboard Maestro Engine"
repeat until window "Keyboard Maestro" exists
delay 1.0E-3
end repeat
tell window "Keyboard Maestro"
-- No offset of cursor:
-- set its position to {mouseX, mouseY}
-- Offset to place cursor on close button:
-- set its position to {(mouseX - 10), (mouseY - 10)}
-- Offset to place cursor on first macro of palette:
set its position to {(mouseX - 70), (mouseY - 50)}
end tell
end tell
end tell
Thanks again! I'll mark your original reply as the solution, since that actually did do the trick!
@rowan here's another method of achieving the same thing but without setting the variable from KM first... basically the AppleScript process that token directly. I'll be honest, I don't 100% understand the array portion, but I found it searching around here and the Late Night Software forum and it works quite well for me.
-Chris
EDIT: FWIW, I added this AppleScript to my personal toggle GMP macro because it's quite convenient
----------------------------------------------------------
# Author: Chris Thomerson
#
# Current Version: 1.1 (Switched to processing the KM token directly in the AppleScript)
# Version History: 1.0 (Initial script)
#
# Created: Wednesday, December 29, 2021
# Modified: Wednesday, December 29, 2021
# macOS: 12.1 (Monterey)
#
# DISCLAIMER
# Permission to use, copy, modify, and/or distribute this
# software for any purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
----------------------------------------------------------
tell application "Keyboard Maestro Engine" to set CurrentMouse to process tokens "%CurrentMouse%" --gets current mouse position from KM
set {mouseX, mouseY} to my mouseCoords(CurrentMouse, ",") --sets mouse coordinates
on mouseCoords(theString, theDelimiter)
set oldDelimiters to AppleScript's text item delimiters -- save delimiters to restore old settings
set AppleScript's text item delimiters to theDelimiter -- set delimiters to delimiter to be used
set theArray to every text item of theString -- create the array
set AppleScript's text item delimiters to oldDelimiters -- restore the old setting
return theArray -- return the result
end mouseCoords
tell application "System Events"
tell application process "Keyboard Maestro Engine"
--pauses until the KM palette appears
repeat until window "Keyboard Maestro" exists
delay 1.0E-3
end repeat
--positions the KM palette
tell window "Keyboard Maestro"
set its position to {(mouseX - 50), (mouseY - 40)}
end tell
end tell
end tell
Hey there, I imagine you could. This screenshot (using UI Browser to see the prompt with list window’s accessibility information) indicates that the list window is structured like the palette windows are. Namely, it’s a window of Keyboard Maestro Engine. So AppleScript should be able to interact with it the same way as a palette.
If this doesn’t make sense let me know and when I have some more time tomorrow I’ll explain in more detail.
Trigger macro by name accessibility screenshot (click to expand/collapse)
Thanks for your quick reply. Issue solved with action Set Next Engine Window Position. Didn't knew that it's possible to use variables instead of fixed x,y-values.