Move the Mouse in DT (SWIFT)

These two Swift Scripts do what their names suggest. They are integrated into Keyboard Maestro. Of course, there are other ways to do this as well.

DT: Move Mouse to Item List.kmmacros.zip (3.4 KB)
DT: Move Mouse to Navigation Bar.kmmacros.zip (3.1 KB)

The mouse is moved (in list view) to the left edge of the selected area. This is handy for dragging actions with the mouse.

This moves the mouse to the cursor or to selected text.
Move Mouse to the Cursor.kmmacros.zip (4.0 KB)

Maybe someone else will find this as useful as I do :slight_smile:

And this does the same in the Finder.
(Thanks, Neil, for showing me this)
Move Mouse to Finder Selection (Swift).kmmacros.zip (3.4 KB)

1 Like

Frank, I don’t seem to get any of these to work - do I need to install anything before I run them?
In KM, I am using shortcuts such as Opt-2, etc, to trigger the actions

You could try to extract the code from the macro (it’s just plist) and run that as a Swift script. Perhaps you’ll get an error message than that indicates where a problem might be.

UI scripting is error-prone and never a robust way to automate an app. Regardless of operating system, language and app.
For example, the script code I saw uses an offset of 10 pixels at a certain point – how does that work if the UI is zoomed?
What happens if a detail in the app‘s UI hierarchy is modified? What about timing issues, eg trying to click a button that has not been fully rendered yet?

2 Likes

I’m assuming you’re running the macro with KM?

If so, KM would let you know if this required additional software is missing: Command Line Developer.

But as @chrillek says, you can also run the Swift script in other ways. I don’t know enough about that, though.

The imported Macro in KM looks like this

image

Ah thanks Christian, this is great advice! I will take time to go through it, and hopefully come back with findings.