Benches macOS

3

scripting a mouse click and drag

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

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.

3 replies

Sign in or join Beachball Help to reply.

  1. 0

    Tony T1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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

  2. 0

    Pierre L.

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  3. 0

    FCPeditor

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    ding ding ding ding we have a winner. I am doing everything I can to get you nominated for employee of the month, thanks for solving this issue for me.