user654936
user654936

Reputation: 213

How do you achieve a click on the screen in Safari using AppleScript?

I am trying to create a script that will click on the specific game "knights of the crystals" then click "Queue all Gifts"

while loop forever

then click "accept"
then do keyboard command "command w"
then wait 5 seconds

I am using AppleScript and this is what I have so far:

tell application "Safari"
    activate
    open location "http://apps.facebook.com/gfriendfinder/?ref=bookmarks&count=0"
    delay 5
    tell application "System Events"
        click at {750, 550}
    end tell
end tell

I'm not sure why the click at function is not working. Is it in the right place?

Upvotes: 1

Views: 4511

Answers (1)

regulus6633
regulus6633

Reputation: 19040

First, it's bad form and could cause issues by having one tell block inside of another when it's not needed. For example you are telling safari to tell system events to click, when you don't need to have safari do that. Safari is not even required for the "open location" command or the "delay" command. So in general do not tell an application to do something if it's not required. Second, I have found that performing clicks doesn't work many times with system events. I have developed a mouse-clicking command line tool to use when that happens. You can get it here. Download that and place it on your desktop, then run this script and see if that helps.

set mouseToolsPath to (path to desktop as text) & "MouseTools"
open location "http://apps.facebook.com/gfriendfinder/?ref=bookmarks&count=0"
delay 5
tell application "Safari" to activate
do shell script quoted form of POSIX path of mouseToolsPath & " -x 750 -y 550 -leftClick"

One other idea would be to learn javascript, because Safari understands javascript and you can probably press the buttons in a Safari web page with that. I'm not a javascript expert though so I can't help with that.

Upvotes: 2

Related Questions