I'm currently evaluating the quality of several 10000s of files containing heart beat profiles of a gastropod (yes!).

To complete this task I have used R to program an interface that allows me to plot one file, decide wether it is good or bad (there's lots of things that go wrong while capturing the heart beat...), click on the appropriate button (OK vs BAD) and proceed to plot the next file.

This is the interface I have to use (there is no substitute for this), and there is no work-around the need to click in either of the buttons (no way to create a shortcut for that button). I could use TAB to cycle through the buttons, but that is totally impractical as it will cycle through the window buttons as well (FILE, EDIT, etc).

Given the previous, I wonder if there is a way to create a keyboard shortcut to simulate a click in a specific place on the screen... this way I could setup 2 shortcuts for the places where the buttons are, thus allowing me to press, for example, OPTION+G for good files and OPTION+B for bad ones without having to guide the mouse to the actual button (remind that I will have to do this > 80000 times...). Many thanks in advance!

  • if you can decide if a file is good or bad by visually examining the data cant the whole accept/reject process be automated.. take the user (you) out of the picture entirely?
    – Sam Axe
    Jan 25, 2013 at 0:34
  • You should be able to do that with automator or applescript
    – MaQleod
    Jan 25, 2013 at 0:47
  • @ Dan-o: I wish!... I do perform an automated analysis on each file that can detect gross errors on the heart beat reading, but most errors are minor and require my input to fix, and therefore I do need to look at every file. The thing is some times I may get, say, 100 files in a row that are good with 1 or 2 in between that are bad. It would be so much comfortable to just press a key to reject those few files without having to reach for the trackpad... again, > 80000 files (I'm guessing it'll be ~2 weeks full work...)
    – ruisea
    Jan 25, 2013 at 2:00
  • @ MaQleod: I have no experience at all with automator routines - can you post/direct me to an example?
    – ruisea
    Jan 25, 2013 at 2:02
  • After a few days testing the answers provided (mine and Lauri's), mine seems to be the one working best. Nevertheless, even with mine I get this strange behavior where after a large amount of consecutive usages of the same automator service (around 1000 times), X11 becomes unresponsive to the service, and I have to reboot to get it working again. Still, totally worth it in terms of productivity...
    – ruisea
    Jan 28, 2013 at 23:50

3 Answers 3


Try assigning a shortcut to a script like this:

tell application "System Events"
    tell (process 1 where frontmost is true)
        click at {60, 5}
    end tell
end tell

Or clicking the buttons directly:

tell application "System Events"
    tell process "AppName"
        -- UI elements of window 1
        click button 2 of window 1
    end tell
end tell
  • I'm sorry Lauri Ranta, but I don't have the knowledge to implement what you suggest... I tried copy&paste your 1st example asIs in the automator services, but to no avail... Can you please elaborate a little more? It does seem more straightforward than my answer...
    – ruisea
    Jan 25, 2013 at 9:40
  • Just save the scripts in AppleScript Editor (as scpt or applescript) and use FastScripts to assign the shortcuts.
    – Lri
    Jan 25, 2013 at 19:02
  • @ Lauri Ranta: OK, but do I paste exactly your examples, word by word, or am I supposed to adjust parts to match my needs?
    – ruisea
    Jan 25, 2013 at 21:56
  • In the first script, just the coordinates. For the second script, you have to enable access for assistive devices in the accessibilty preferences and figure out how to specify the buttons (UI Browser can help with that).
    – Lri
    Jan 25, 2013 at 22:00
  • OK, your example works flawlessly. I only tried the 1st one. For the lay ones like me, I edited your answer to include a few more steps. Thanks a lot, Lauri!
    – ruisea
    Jan 25, 2013 at 22:19

I guess this means I should have done an even more thorough search before posting the question, but I'm guessing this will also be useful to other users, so not all is lost.

While waiting for answers, and after feeling pushed by MaQleod to search a little more about automator routines that could do what I needed, I found a solution.

I found this free little shell / Terminal application called "cliclick" (download from http://www.bluem.net/en/mac/cliclick/ ). It allows performing mouse commands via Terminal very easily.

I then hit automator and created the following service automator script:

  • service receives no input
  • used a 'run shell script' action
  • I deleted the 'cat' string that pops up automatically
  • I entered 'cliclick -w 100 m:970,870 c:.'
    • '-w 100' = wait 100 milliseconds after each step
    • 'm:970,870' = move mouse to x=970 and y=870
    • 'c:.' = click at the present position

I got the coordinates by simply using the COMMAND+SHIFT+4 shortcut, which immediately turns the mouse pointer into a crosshair that also displays the screen coordinates...

With this little script saved as a service, I then just had to go to System Preferences/Keyboard/Keyboard Shortcuts/Service, look for my newly saved automator services, and set a keyboard shortcut, and voilá!

Hope someone else finds this useful.

  • Thank you very much for your awesome answer. It does help a lot.
    – whitesiroi
    Apr 3, 2016 at 10:21

I think you have to go with xdotool

It's unix, very well documented, and since you are a programmer, I guess you will have no problem instaling it. I ll love to hear how it works on a Mac.

  • Thanks H_7, from what I read it seems that could work. In the meantime, however, I found another solution I'll be posting right away - it follows a similar logic as what I would be trying with xdotool if hadn't been successful yet. Cheers.
    – ruisea
    Jan 25, 2013 at 3:41
  • @ruisea oh please let me know your way too, waiting the post. good luck on this !
    – H_7
    Jan 25, 2013 at 3:43
  • 1
    ahah, I have too low reputation, can only answer my own question within 4 hours... well, I'll come back then
    – ruisea
    Jan 25, 2013 at 4:04
  • remember to upvote mine -) if you think its ok, of course. =D
    – H_7
    Jan 25, 2013 at 5:03
  • 1
    Yes, I'm pretty sure your suggestion would also work (but I haven't tried it) as it definitely allows moving the mouse cursor to an xy coordinate, and then click, which is what is need for this task. It even seems to me that xdotool is more powerful than the solution I'm posting soon, albeit slightly less straightforward. As for the upvote, I had already tried that but again, I don't have the minimum reputation required. Will definitely endorse that, as I'm 95% sure your suggestion would work...
    – ruisea
    Jan 25, 2013 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.