Friday, March 22, 2019

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

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

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: 667

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: 5

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: 667

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: 5

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: 667

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

 

#7 2018-12-17 03:09:30 pm

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

Re: simulating mouse clicks macos

hi

& sorry for my late reply.....for some reason what you suggested is not working for me neither.

Anything else i can try ?



Thx in advance

Offline

 

#8 2018-12-19 09:12:48 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 378

Re: simulating mouse clicks macos

Things that can click from Applescript you may try:

Ones it looks like you've tried:
- System Events
- ClickClick

Things you might still try:
- AS Toolbox  https://astoolbox.wordpress.com (note that, I've heard that as of Mojave, OSAXen must be script embedded, not installed system-wide)
- MouseTools http://www.hamsoftengineering.com/codeS … Tools.html
- Python https://macscripter.net/viewtopic.php?id=46154


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#9 2018-12-22 04:14:01 am

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

Re: simulating mouse clicks macos

Thx t.spoon,

I have managed to simulate clicks by python, but now i have to integrate the apple script simulation with the python.


Thats a challenge for me since I need to sync those two scripts now......
Any clue how I do that ?



Thx in advance,
Samuel

Offline

 

#10 2018-12-26 01:50:22 pm

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

Re: simulating mouse clicks macos

hi
try something like this

Applescript:

do shell script "python /Users/Samuel_Jr/Desktop/YourScriptName.py"


Cheers
Budgie

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

Offline

 

#11 2018-12-26 02:25:57 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 378

Re: simulating mouse clicks macos

Samuel_Jr,

but now i have to integrate the apple script simulation with the python



Sorry, not sure I'm understanding the problem... the example script I linked to made the Python an Applescript handler for click-and-drag operations. Doesn't making the python into an Applescript handler integrate the two for you?


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)