Display Global Palette at Cursor?

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...

1 Like

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.

14)Global Macro Palette- Place under mouse.kmmacros (4.1 KB)

Macro screenshot (click to expand/collapse)

3 Likes

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 :thinking: :yum: )?

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 :sweat_smile:

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
3 Likes

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!

Glad to help! Always nice when a plan comes together! :grin:

1 Like

@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 :+1:t2:

----------------------------------------------------------
# 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

14)Global Macro Palette- Place under mouse copy.kmmacros (4.0 KB)

Macro screenshot (click to expand/collapse)

2 Likes

Not really seeing what the advantage is, so I'll stick with the original solution.

Did you actually upgrade from Big Sur to Monterey between just the two iterations of your AppleScript? :exploding_head::face_with_hand_over_mouth::rofl:

The only advantage is everything is done from the AppleScript which reduces how many actions you need in your macro. That’s all.

Haha no, I just switched to my MacBook which has Monterey and since it works on there too I added that to the script :sweat_smile:

Can you adapt it to work with Prompt with list?

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.

1 Like

Oh yea even better. That’s a new to version 10 feature which I don’t think was around yet when we were talking about this last year.

1 Like

I'm not sure if "thank you" posts are appropriate here (vs liking a post), but I wanted to say thanks for this!

1 Like

If you ask me, saying “thank you” to somebody is always appropriate, whether on a forum or in real life. :wink::grin:

2 Likes

Agreed!

Some forums have strict rules about thank-you posts to cut down on clutter and unnecessary notifications for users. But this is the kind of clutter I can live with :slight_smile:

2 Likes