Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

scripting a mouse click and drag

does anyone know how to script a mouse click and drag. I tried XTools. No luck. What about Cliclick. I had tons of success with TextCommands but I dont know how to get OSAX plugin code to work. Thanks in advance.

I am trying to move a desktop clock (QuartzClock) from the center of the screen to the side.

MBP17, Mac OS X (10.6.3)

Posted on Jul 15, 2010 5:13 AM

Reply
3 replies

Jul 15, 2010 6:13 AM in response to FCPeditor

I tried (unsuccessfully) to find a mouse move and click solution in Applescript.
My search brought me to this site: http://www.geekorgy.com/index.php/2010/06/python-mouse-click-and-move-mouse-in-a pple-mac-osx-snow-leopard-10-6-x/

The following python script will move an object from position 60.100 to 60.300


#!/usr/bin/python
import sys
import time
from Quartz.CoreGraphics import * # imports all of the top-level symbols in the module
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclickdn(posx,posy):
mouseEvent(kCGEventLeftMouseDown, posx,posy);
def mouseclickup(posx,posy):
mouseEvent(kCGEventLeftMouseUp, posx,posy);
def mousedrag(posx,posy):
mouseEvent(kCGEventLeftMouseDragged, posx,posy);
ourEvent = CGEventCreate(None);
currentpos=CGEventGetLocation(ourEvent); # Save current mouse position
mouseclickdn(60, 100);
mousedrag(60, 300);
mouseclickup(60, 300);
time.sleep(1);
mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position


See also:
http://developer.apple.com/mac/library/documentation/Carbon/Reference/QuartzEven tServicesRef/Reference/reference.html
http://developer.apple.com/graphicsimaging/pythonandquartz.html
Tony

Jul 15, 2010 7:07 AM in response to FCPeditor

Assuming you are talking about QuartzClocks 1.3.6 by Chris Kent, you might also try something like this:

*tell application "System Events" to set position of window 1 of process "QuartzClocks" to {0, 22}*

(You must have enabled the Accessibility Frameworks by clicking the checkbox labeled "Enable access for assistive devices" in the Universal Access System Preference pane.)

Message was edited by: Pierre L.

scripting a mouse click and drag

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