The question asked by the OP is not interesting. Since it has been asked on the forums many times and exhaustive answers have already been given to it. I am aware of at least 3 methods for moving the mouse pointer on the screen.
using a third-party utility like ClicClick, 2) using Python, 3) using CGPostMouseEvent. Moreover, the latter method is not recommended and has been deprecated, although it still works …
All examples of these methods are already published on this site and the OP can find them himself.
It would be much more interesting if someone shared a concrete example of the new method you point to here. I have not seen such an example yet, so I have a hunch that it is difficult or impossible to apply it with the AsObjC language.
This is a total hack, but does work, although it should not work.
So use with caution.
use framework "Foundation"
use framework "CoreGraphics"
set cursorPoint to current application's NSMakePoint(500, 500)
set theError to current application's CGDisplayMoveCursorToPoint(current application's CGMainDisplayID(), cursorPoint)
The “theError” variable should hold a CGError if it fails, but I thought that AS can’t handle CGError’s.
Also the “CGMainDisplayID” should be a “UInt32” data type, but you can pass any integer value in the above code, which again should not be working.
So I’m not sure why it’s working, but it does on “Mojave” at least, so again use with caution.
I’m guessing that the “theError” is probably returning “0” for success, and “1” if a failure occurs.
So an if statement might be a good idea, like this.
use framework "Foundation"
use framework "CoreGraphics"
set cursorPoint to current application's NSMakePoint(500, 500)
set theError to current application's CGDisplayMoveCursorToPoint(current application's CGMainDisplayID(), cursorPoint)
if theError = 0 then
return "SUCCESS"
else if theError = 1 then
return "FAILURE"
end if
But just a guess, maybe Shane knows how to handle CGError’s in AppleScript.
This is a better solution, because it does not rely on a display ID number, but automatically uses the default or main screen.
use framework "Foundation"
use framework "CoreGraphics"
set cursorPoint to current application's NSMakePoint(500, 500)
set theError to current application's CGWarpMouseCursorPosition(cursorPoint)
if theError = 0 then
return "SUCCESS"
else if theError = 1 then
return "FAILURE"
end if