Thursday, December 13, 2018

#1 2018-12-05 03:22:13 am

Samuel_Jr
Member
Registered: 2018-12-04
Posts: 3

simulating mouse clicks macos

Hi all,

I am trying to simulate mouse clicks via my  script editor (using macOS High Sierra).
Going through the forums on the internet, nothing really worked.

Can someone help here ?


Thx in advance,
Samuel

Model: MacBook Air
Browser: Safari 537.36
Operating System: macOS 10.13

Offline

 

#2 2018-12-05 03:32:21 pm

Budgie
Member
From:: New Zealand
Registered: 2005-02-22
Posts: 661

Re: simulating mouse clicks macos

Hi and welcome to MacScripter

A few suggestions to start:

System events can click, but finding the co-ordinates can be a bit hit and miss, using code something like this:

Applescript:

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

Cliclick from  https://www.bluem.net/en/projects/cliclick/ is very good, using code
something like this, the "dc" stands for double click.

Applescript:

set cliclick_Path to POSIX path of (((path to desktop) as text) & "cliclick")
set cliclick_Path_Posix to POSIX path of cliclick_Path
do shell script quoted form of cliclick_Path_Posix & space & "dc:100,100" -- change the x & y coodinates

Mouse Tools from here, will help getting the coordinates of the mouse cursor, which you can then use to put into ether of the above

http://www.hamsoftengineering.com/codeS … Tools.html

Last edited by Budgie (2018-12-05 06:30:49 pm)


Cheers
Budgie

"There's no shame in accepting aid from others... but perhaps there is a  responsibility."    - Batman

Offline

 

#3 2018-12-06 04:27:51 pm

Samuel_Jr
Member
Registered: 2018-12-04
Posts: 3

Re: simulating mouse clicks macos

Hi Budgie,

Thx for your repy.
I was trying to run your 1st sript;
tell application "System Events"
   click at {100, 100}
end tell

But nothing happened.

Also when i was trying to run the 2nd in the following way:
tell application "Google Chrome"
    activate
    delay 7
end tell

set cliclick_Path to POSIX path of (((path to desktop) as text) & "cliclick")
set cliclick_Path_Posix to POSIX path of cliclick_Path
do shell script quoted form of cliclick_Path_Posix & space & "dc:100,100" -- change the x & y coodinates


I got the following error;
error "sh: /Users/Inon/Desktop/cliclick: No such file or directory" number 127


What do I miss here ?


Thx in advance,
Samuel

Offline

 

#4 2018-12-06 04:36:36 pm

Budgie
Member
From:: New Zealand
Registered: 2005-02-22
Posts: 661

Re: simulating mouse clicks macos

hi

this definitely works, you may not have seen anything happen because you don't have anything sitting at those coordinates, try running mouse tools to get the coordiantes of your mouse cursor so it clicks on say the collapse button in a window.

Applescript:

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

for the second issue, once you dowloaded the cliclick dmg and opened it, did you put the downloaded cliclick executable on your desktop?, as the script works fine.


Cheers
Budgie

"There's no shame in accepting aid from others... but perhaps there is a  responsibility."    - Batman

Offline

 

#5 2018-12-07 01:39:14 pm

Samuel_Jr
Member
Registered: 2018-12-04
Posts: 3

Re: simulating mouse clicks macos

Hi

I was trying this script (by using an excell sheet as a grid);
tell application "Microsoft Excel"
    activate
    delay 2
end tell


tell application "System Events"
    repeat 10 times
        click at {400, 100}
    end repeat
end tell

tell application "System Events"
    repeat 10 times
        click at {800, 1300}
    end repeat
end tell

tell application "System Events"
    repeat 10 times
        click at {1400, 1400}
    end repeat
end tell



but i got this error;

error "System Events got an error: AppleEvent timed out." number -1712



can you plz expalin what is wrong ?


thx in advance,
Samuel

Offline

 

#6 2018-12-10 03:18:03 pm

Budgie
Member
From:: New Zealand
Registered: 2005-02-22
Posts: 661

Re: simulating mouse clicks macos

Hi
Try telling system events to tell process "Microsoft Excel"

Applescript:

activate application "Microsoft Excel"
delay 2
tell application "System Events" to tell process "Microsoft Excel"
   
   repeat 10 times
       click at {400, 100}
   end repeat
   
   repeat 10 times
       click at {800, 1300}
   end repeat
   
   repeat 10 times
       click at {1400, 1400}
   end repeat
   
end tell

Last edited by Budgie (2018-12-11 07:18:09 pm)


Cheers
Budgie

"There's no shame in accepting aid from others... but perhaps there is a  responsibility."    - Batman

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)