How to send the mouse pointer to a certain location with AppleScript?

Hi all!

I've already posted something along those lines a few months ago, but I've forgotten how it's done: I'd like to write a very simple AppleScript to send the mouse pointer to center screen on startup. I'd save the script as an application, add it to my startup items and hope for the best...

I thought the proper syntax to move the mouse pointer in AppleScript was "move mouse" without the quotes, but every time I try it, I get an error message, so I'm kinda lost here...

What's wrong with the following instruction?

move mouse {720, 450} -- {from left, from top}

(My screen resolution is set to 1440x900 px)

Shouldn't it be enough?

Message was edited by: Didier Caizergues

MBP Core Duo 1,83GHz 15", Mac OS X (10.4.11), Me love you cookies lo-oong time!

Posted on Jun 10, 2009 8:52 AM

Reply
20 replies

Jun 10, 2009 12:58 PM in response to OneCatFamily

do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep 'Resolution'" -- get info
tell the result to set {DisplayWidth, DisplayHeight} to {word 2, word 4} -- get resolution
--move mouse {DisplayWidth div 2, DisplayHeight div 2} -- center mouse
(*
move mouse {670, 13} --sound
click mouse
move mouse {673, 96} --sound level
click mouse
*)
move mouse {555, 282} -- center mouse
click mouse
(*
Anyway, you can do what you want with some scripting. First, there is the XTools scripting addition, which will give AppleScript the ability to move the mouse. Once the scripting addition is copied to either the /Library/ScriptingAdditions or ~/Library/ScriptingAdditions folders, you can use it's commands. Next, you will need to place a script application into your login items (System Preferences > Accounts > Login Items) that will move the mouse when you log in:
*)

Jun 12, 2009 11:43 AM in response to OneCatFamily

Works for me. Ran from script editor.

Check for an earlier version in the directories. My other two directories do not exit: ~/Library/ScriptingAdditions/ & /Library/ScriptingAdditions/

My earlier doc may be incomplete. From the manual:

Installation :


XTool is not different from other osaxen, simply drag XTool in one of the following locations (create the directory if it does not exist) :

a : ~/Library/ScriptingAdditions/
b : /Library/ScriptingAdditions/
c : /System/Library/ScriptingAdditions/


I have it in directory
-- /System/Library/ScriptingAdditions/ :
mac $ ls -l /System/Library/ScriptingAdditions/
total 0
drwxr-xr-x 3 root wheel 102 Jan 10 2007 ColorSyncScripting.app/
drwxr-xr-x 3 root wheel 102 Feb 11 2003 Digital Hub Scripting.osax/
drwxr-xr-x 3 root wheel 102 Jul 29 2002 FontSyncScripting.app/
drwxr-xr-x 3 root wheel 102 Jul 29 2002 Image Capture Scripting.app/
drwxr-xr-x 3 root wheel 102 Jan 10 2007 Keychain Scripting.app/
drwxr-xr-x 3 root wheel 102 Dec 18 2002 StandardAdditions.osax/
drwxr-xr-x 3 root wheel 102 Jul 29 2002 URL Access Scripting.app/
drwxr-xr-x 3 mac wheel 102 Feb 25 2007 XTool.osax/
mac $


Robert

Message was edited by: rccharles

Jun 12, 2009 12:39 PM in response to OneCatFamily

You sure you got the right version?

http://www.lestang.org/osax/XTool/
XTool-2.0-src.dmg.tgz

Perhaps you got it in too many places.

You sure you got the right permissions?

Use the terminal to check things out:
Macintosh-HD -> Applications -> Utilities -> Terminal
mac $ ls -l /System/Library/ScriptingAdditions/
total 0
drwxr-xr-x 3 root wheel 102 Jan 10 2007 ColorSyncScripting.app/
drwxr-xr-x 3 root wheel 102 Feb 11 2003 Digital Hub Scripting.osax/
drwxr-xr-x 3 root wheel 102 Jul 29 2002 FontSyncScripting.app/
drwxr-xr-x 3 root wheel 102 Jul 29 2002 Image Capture Scripting.app/
drwxr-xr-x 3 root wheel 102 Jan 10 2007 Keychain Scripting.app/
drwxr-xr-x 3 root wheel 102 Dec 18 2002 StandardAdditions.osax/
drwxr-xr-x 3 root wheel 102 Jul 29 2002 URL Access Scripting.app/
drwxr-xr-x 3 mac wheel 102 Feb 25 2007 XTool.osax/
mac $ ls -ld /System/Library/ScriptingAdditions/
drwxr-xr-x 10 root wheel 340 Mar 15 22:44 /System/Library/ScriptingAdditions//
mac $


Message was edited by: rccharles

Jun 12, 2009 2:15 PM in response to rccharles

Here's what I get from Terminal:

Last login: Fri Jun 12 20:48:48 on console
Welcome to Darwin!
put92-2-82-224-221-238:~ didiercaizergues$ ls -l /System/ScriptingAdditions/
ls: /System/ScriptingAdditions/: No such file or directory
put92-2-82-224-221-238:~ didiercaizergues$ ls -l /System/Library/ScriptingAdditions/
total 0
drwxr-xr-x 3 root wheel 102 Mar 28 18:40 ColorSyncScripting.app
drwxr-xr-x 3 root wheel 102 Jan 14 2006 Digital Hub Scripting.osax
drwxr-xr-x 3 root wheel 102 Jan 14 2006 FontSyncScripting.app
drwxr-xr-x 3 root wheel 102 Mar 28 18:40 Image Capture Scripting.app
drwxr-xr-x 3 root wheel 102 Jan 26 2006 Keychain Scripting.app
drwxr-xr-x 3 root wheel 102 Feb 14 2006 StandardAdditions.osax
drwxr-xr-x 3 root wheel 102 Jan 14 2006 URL Access Scripting.app
drwxr-xr-x 11 didierca didierca 374 Feb 26 2007 XTool
put92-2-82-224-221-238:~ didiercaizergues$

I put it in System/Library/ScriptingAdditions alone, and deleted the others. I'm surprised not to get the same results as you on the last line of the list, though. You have 3 and I've got 11. Does it mean I'm richer than you...? 😉

I'm going to download it again, just in case I got the wrong one...

Jun 13, 2009 2:02 AM in response to OneCatFamily

I think I got it! I had the whole Xtools folder in the right directory, but when I mounted the new Xtools dmg file you pointed me at, I managed to drag n drop the osax file directly in the ScriptingAdditions folder in /System/Library, and guess what?

It worksssss!!!

I saved the script as an app and inscribed it in the startup menu items. I'll see on next boot if my pointer does move to center screen or not...

Thanks a bunch to y'all!

Jun 13, 2009 6:55 AM in response to OneCatFamily

I thought I had it... The mouse pointer does move to center screen on startup, BUT, and that's a big but, the application remains opened in the Dock, and I have to close it manually...

I've saved the script as an application, to open in background (which obviously it doesn't...) and on startup (which it does). Now, how do I edit the script so that the application called MoveMouse (that's how I've named it) quits after moving the mouse pointer to center screen?

Jun 13, 2009 12:12 PM in response to OneCatFamily

Well you can blame the documentation:
"XTool is not different from other osaxen, simply drag XTool in one of the following locations (create the directory if it does not exist)"

Using XTool.osax would be better. I have file extensions turned on too!

--------

It is how you save the script:

!http://farm4.static.flickr.com/3616/3622195229_4e82e7571a.jpg?v=0!

Notice how all the boxes are not checked. That's what you need.

Robert

Jun 15, 2009 1:10 AM in response to rccharles

Alright, here's what I have now (I should add that my script now works flawlessly, thanks to the numerouse advice I received here):

Last login: Mon Jun 15 09:54:50 on console
Welcome to Darwin!
put92-2-82-224-221-238:~ didiercaizergues$ ls -l /system/Library/ScriptingAdditions/
total 0
drwxr-xr-x 3 root wheel 102 Mar 28 18:40 ColorSyncScripting.app
drwxr-xr-x 3 root wheel 102 Jan 14 2006 Digital Hub Scripting.osax
drwxr-xr-x 3 root wheel 102 Jan 14 2006 FontSyncScripting.app
drwxr-xr-x 3 root wheel 102 Mar 28 18:40 Image Capture Scripting.app
drwxr-xr-x 3 root wheel 102 Jan 26 2006 Keychain Scripting.app
drwxr-xr-x 3 root wheel 102 Feb 14 2006 StandardAdditions.osax
drwxr-xr-x 3 root wheel 102 Jan 14 2006 URL Access Scripting.app
drwxr-xr-x 3 didierca wheel 102 Feb 26 2007 XTool.osax
put92-2-82-224-221-238:~ didiercaizergues$

I'm back to normal, right?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to send the mouse pointer to a certain location with AppleScript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.