Mouse click at a precise position

Hi,

I’m working on Mac Os Monterey.
After opening on Mac OS “Script Editor”, I entered this code:

			tell application "System Events"
				tell process "Google Chrome"
					click at {175, 300}
				end tell
			end tell

Mouse click does not work.
Why?
There is surely something forgotten to install

Thank you for your help

The following works on my Ventura computer:

tell application "System Events"
	click at {15, 15}
end tell

The following also works on my computer, but I’m not sure if it’s worth using, because the coordinates are global coordinates.

tell application "System Events" to tell process "Google Chrome"
	set frontmost to true
	delay 0.5
	click at {15, 15}
end tell

BTW, if you want to click at a specific location within Google Chrome, you can try the following:

set clickOffset to {100, 100} -- user set as desired
tell application "System Events"
	tell process "Google Chrome"
		set frontmost to true -- assumes Chrome already running
		delay 0.5 -- or use repeat loop
		set thePosition to position of window 1
	end tell
	click at {(item 1 of clickOffset) + (item 1 of thePosition), (item 2 of clickOffset) + (item 2 of thePosition)}
end tell

Try adding this the beginning of your script:

tell application "Google Chrome" to activate
1 Like

click at has unfortunately been unreliable for some time.

You can use the very useful command-line utility cliclick (i.e. CLI-Click) from AppleScript to accomplish this reliably. It’s available on Homebrew.

to clickAt(global_coordinates)
	set coordinates_s to "=" & ((item 1 of global_coordinates) div 1 as string) & ",=" & ((item 2 of global_coordinates) div 1 as string)
	GL's doShellScript(quoted form of CLICLICK_PATH & " c:" & coordinates_s)
	return global_coordinates
end clickAt

Just make sure you replace CLICLICK_PATH with the path to the binary.

1 Like