Here's my Keyboard Maestro solution:
Is yours much the same, or something different ?
Here's the code I've been playing around with to achieve the same sort of thing:
ObjC.import('Cocoa');
nil=$();
const sys = Application('System Events');
const win = sys.processes.whose({ 'frontmost': true }).windows[0];
const pos = {x: win.position()[0][0] + 100, y: win.position()[0][1] + 100};
const mousedownevent = $.CGEventCreateMouseEvent(nil,
$.kCGEventLeftMouseDown,
pos,
nil);
$.CGEventPost($.kCGHIDEventTap, mousedownevent);
$.CFRelease(mousedownevent);
const mouseupevent = $.CGEventCreateMouseEvent(nil,
$.kCGEventLeftMouseUp,
pos,
nil);
$.CGEventPost($.kCGHIDEventTap, mouseupevent);
$.CFRelease(mouseupevent);
This works fine in Script Editor, but it doesn't fully issue the click if run inside Keyboard Maestro. It may be because KM uses osascript
(I wish it didn't), and perhaps the CG events need a GUI context to operate in.
Thankfully, FastScripts uses the native AppleScript engine (whatever the correct terminology for that is), so this script should work via that.
Happy to hear your thoughts. Have you come across any other/better methods ?