I’m working on my first AppleScriptObjC project and naturally getting a touch muddled ” I only know as much Cocoa as one can deduce by wandering around the X-Code documentation. Anyway, I want a windowless AppleScriptObjC app to produce a mouse click at a specific screen location, say (100, 100). I’ve actually figured out how to do this in Cocoa:
I used the “NSEvent” method “eventWithCGEvent:” to convert my CGEvents into NSEvents, and it appears that you were basically right in your guesses for parameter values. However, “pressure” should be 1 not 0.
I tried to use these values to create an event using this code:
This code did nothing. I also replaced the NULL’s with “[NSGraphicsContext currentContext]” without effect and tried “[NSApp sendEvent: myEvent1]” in place of “[NSApp postEvent: myEvent1 atStart: YES]”. I think the problem maybe related to the timestamp, but I’m not sure.
I suspect that the problem is that you’re sending the event to your app, so it must be handled by your app. What you need to do is insert it somewhere before the app, which probably means using a lower-level I/O C API.
Assuming you are right and this approach is a dead end, this is what I did instead. I used my working Core Graphics program to make a sub-class of “NSEvent” ” “MyNSEvent”. I followed the Rectangle/Square example at