MouseTools
version 0.5
Requires Mac OS X 10.4 or higher


HAMSoft Engineering allows free use of this code and/or software in its "as is" condition. HAMSoft Engineering disclaims any liability of any kind for any damages whatsoever resulting from the use of this code and/or software. If you find it useful please consider making a donation to help HAMSoft Engineering stay in business.

download the compiled command line tool
download the source code project

This command line tool will help you perform tasks with your mouse.
NOTE: by default screen coordinates are measured from the top-left corner of the screen but with the [-b] switch they can be measured from the bottom-left.

SWITCHES:
[-h] return this help text
[-b] coordinates are measured from bottom-left corner of the screen
[-location] return the current mouse location
[-x "xValue" -y "yValue"] move the mouse to the {xValue, yValue} location
[-mouseSteps numSteps] move mouse in number-of-steps to the location
[-leftClick] perform a mouse left-click at the current mouse location
[-doubleLeftClick] perform a mouse double-click with the left mouse button
[-rightClick] perform a mouse right-click at the current mouse location
[-shiftKey] shift key down, useful when performing a left-click event
[-commandKey] command key down, useful when performing a left-click event
[-optionKey] option key down, useful when performing a left-click event
[-controlKey] control key down, useful when performing a left-click event
[-leftClickNoRelease] perform a mouse click and do not release the mouse click
[-releaseMouse] release the mouse after using -leftClickNoRelease

EXAMPLES:
1. get mouse location (measured from top-left)
MouseTools -location

2. get mouse location (measured from bottom-left)
MouseTools -b -location

3. move the mouse to a screen location
MouseTools -x xValue -y yValue

4. move the mouse in 1000 steps to a screen location
MouseTools -x xValue -y yValue -mouseSteps 1000

5. right-click the mouse at the current mouse position
MouseTools -rightClick

6. move the mouse to the given coordinates and perform a left-click
MouseTools -x xValue -y yValue -leftClick

7. move the mouse to the given coordinates and perform a shift-click
MouseTools -x xValue -y yValue -leftClick -shiftKey


Example usage of the tool with applescript:
Open this Script in your Editor

-- get the current mouse coordinates (measured from top-left corner of screen)

set mouseToolsPath to (path to home folder as text) & "UnixBins:MouseTools"


delay 3 -- 3 seconds after starting the script to move the mouse where you want

set {x, y} to paragraphs of (do shell script quoted form of POSIX path of mouseToolsPath & " -location")


Example usage of the tool with applescript:
Open this Script in your Editor

-- move the mouse to the x/y coordinates (as measured from the top-left part of the screen) and perform a mouse left-click

set mouseToolsPath to (path to home folder as text) & "UnixBins:MouseTools"

set x to 164

set y to 114


do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (x as text) & " -y " & (y as text) & " -leftClick"


Example usage of the tool with applescript:
Open this Script in your Editor

-- move the mouse to the x/y coordinates in 1000 steps

set mouseToolsPath to (path to home folder as text) & "UnixBins:MouseTools"

set x to 164

set y to 114


do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (x as text) & " -y " & (y as text) & " -mouseSteps 1000"