1

I get the error: "Can’t make {x:651.0, y:675.0} into type real." number -1700 from {x:651.0, y:675.0} to real"" when I run this script. I don't know why this happens! Comes from an autoclicker I made, Very simple, but it works with slightly obscure methods (Credit: Clicker, Mouse Position) . Code:

use framework "Foundation"
use scripting additions

set theList to current application's NSEvent's mouseLocation()

(*
set xCoord to theList's x
set yCoord to theList's y
*)
round (theList)
tell application "System Events"
    click at {theList}
end tell
  • You can also use as integer instead of round, e.g.: set xCoord to theList's x as integer and set yCoord to theList's y as integer – user3439894 Sep 14 '17 at 20:26
0

The error you're getting is because you can't round() a structure as a whole, so you need to round its individual components. Replace this:

round (theList)
set theList's x to round (theList's x)
set theList's y to round (theList's y)

Then you'll need to fix a subsequent error caused by theList having x and y keys. Replace this:

  click at {theList}
    click at {theList's x, theList's y}
  • Now I get this error at the "click at" line: System Events got an error: Script Editor is not allowed assistive access." number -25211 – HERECOMESTHEMONEY Sep 14 '17 at 21:21
  • @here That’s just because you haven’t given Script Editor permission to control your system. Follow the instructions in the other prompt dialog which appears to open System Preferences and give permission. – grg Sep 14 '17 at 21:56
  • This computer is a work computer, and they have restricted it. I can't do that. They even added Firmware. That sucks. – HERECOMESTHEMONEY Sep 14 '17 at 22:46
0

The error is because you're trying to round the entire record which is {x:651.0, y:675.0}. Instead, round each variable something like this:

use framework "Foundation"
use scripting additions

set theList to current application's NSEvent's mouseLocation()

set xCoord to round theList's x
set yCoord to round theList's y

--round (theList)
tell application "System Events"
    click at {xCoord, yCoord}
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .