Hi, @peternlewis. In the above submacro, I use the following AppleScript to get the position of a palette created with the Show Palette of Macros action.
tell application "System Events"
tell process "Keyboard Maestro Engine"
get position of window 1
end tell
end tell
I tried to retrieve the bounds, but got these errors:
2023-11-17 10:01:54 Action 15394072 failed: Execute an AppleScript failed with script error: text-script:109:115: execution error: System Events got an error: Can’t get bounds of window 1 of process "Keyboard Maestro Engine". (-1728)
When I look at the Keyboard Maestro Engine AppleScript Dictionary it seems that bounds should be available. What am I missing? TIA
I was hoping to get the bounds so that offset could be defined as a percentage of palette width and palette height. In the above macro, I resorted to using absolute pixels from the palette top-left.
2023-11-18 12:4619 EST Update: I discovered that I can return the size, so I can achieve my objective.
tell application "System Events"
tell process "Keyboard Maestro Engine"
tell window 1
set lstPosition to position
set lstSize to size
return lstPosition & lstSize
end tell
end tell
end tell
However, I still don't understand why bounds seems to be invalid.
This is a really nice touch, and something I think might be applicable in quite a few scenarios. Well done @_jims !
I wonder if perhaps our two approaches could be combined, to give the user the option to:
move the palette to the mouse or
move the mouse to a position on the palette or
both
Also, it would be quite slick if we could add an action group to the submacro that, if enabled, will prompt the user to click (or press a modifier) at the position on the palette that they would like the mouse to arrive at. The offset coordinates would then be displayed in a window, ready to be pasted. This may be overkill, as it's not hard to use the screenshot tool to see x,y, but it did occur to me.
As written, by using the Mouse Absolute Offset it can be moved within the palette. (It would be nice to have the capability to specify a percent x & y, but I don't know how to retrieve the palette bounds–see post above.) Am I missing your point?
both as in either or? Or do you want them to both move and split the difference? Or move to some fixed coordinates not related to either?
Sounds pretty cool, but seems like you would always want that group enabled; it would be activated based on some passed value via the With Parameter. Thoughts?
I meant that the palette could appear at the mouse position and the mouse could move to a predetermined position relative to it. Kind of what I did in my version but with your finessed approach.
Possibly, if you wanted to move the mouse as part of the subroutine. If a palette is small, you may only wish to have it appear next to the mouse.
If you are able to position the palette at the current mouse position and also position the mouse relative to the palette's corner, then all bases are covered.
Yes, my mistake. Thanks for pointing that out. I will fix that note soon. I’m working on Version 2 that will accept percentage offsets as well as absolute offsets.
The Mouse Offset can now be expressed in percentage of palette width or height. For example 50%,10 would move the mouse to the middle of the palette, 10 pixels from the top.
Sorry, @peternlewis, originally I put the wrong error from Engine.log in the post. I've corrected it above.
The script works for me when I combine position & size, but not when I attempt to use bounds. I'll send you a DM which will better demonstrate the issue. Thanks!
Your script is not accessing the Keyboard Maestro at all, the Keyboard Maestro Engine’s dictionary is irrelevant because your script is not asking Keyboard Maestro for any information.
tell application "System Events"
tell process "Keyboard Maestro Engine"
get position of window 1
end tell
end tell
is not using Keyboard Maestro Engine’s dictionary, or talking to the Keyboard Maestro Engine at all.
It is talking to the System Events application. And it is asking System Events about its process named Keyboard Maestro Engine, and is asking System Events about that processes window.
Streamlined the logic in the first Group action. This group includes logic to protect old calling macros by confirming that this macro was properly upgraded.
Bug fix: When I created Version 1 of this submacro, I began by downloading and modifying a similar macro by @noisneil. In hindsight, that was a big mistake because Version 1 (and Version 2) of this submacro shared the same UUID as @noisneil's submacro. That causes problems that I won't detail here; but the issue has been resolved with Version 3+. There is one upgrade complication, however (only for Version 3): calling macros to Version 1 or Version 2 will need to be repaired: the Execute a Macro actions will need to be modified to refer to this Version 3. Alternatively, Version 3+ could be run from the Keyboard Maestro Editor to create a new caller and the Execute a Macro action from the new caller could be copied to the old callers.
No functional change; just minor changes to the dialog messages in the first Group action: To protect old callers, confirm that the macro was properly upgraded.
For the Group action ‘To protect old callers, confirm that the macro was properly upgraded’ moved the logic to a subroutine (s.𝗸𝗺⇾CheckSubUUID).*
Bug fix: If there was an active Keyboard Maestro Search (top-right), the icon intended for the new calling macro was applied to the enclosing macro group. (Thanks to @noisneil for reporting the issue.)