Mouse Move shell app

Hello.

Is there shell application that supports 'press and hold' function? I used 'cliclick' shell application where it's not possible. Also tried 'MouseTools' shell app where according to manual such possibility exists but on my Maverics always returns error in console:


post_filtered_event_tap_data: Sender is prohibited from synthesizing events


and it doesn't work

Posted on Nov 25, 2013 5:03 AM

Reply
2 replies

Nov 25, 2013 5:40 AM in response to M1hail

You can do it with python:


From: http://www.geekorgy.com/index.php/2010/06/python-mouse-click-and-move-mouse-in-a pple-mac-osx-snow-leopard-10-6-x/


##############################################################

#

# Python OSX MouseClick

#

# (c) 2010 Alex Assouline, GeekOrgy.com

#

##############################################################

importsys

try:

xclick=int(sys.argv[1])
yclick=int(sys.argv[2])
try:
delay=int(sys.argv[3])
except:
delay=0
except:
print "USAGE mouseclick [int x] [int y] [optional delay in seconds]"
exit()

print "mouse click at ", xclick, ",", yclick," in ", delay, "seconds"

# you only want to import the following after passing the parameters check above, because ‘importing’ takes time, about 1.5s
# (why so long!, these libs must be huge : anyone have a fix for this ?? please let me know.)

import time
from Quartz.CoreGraphics import CGEventCreateMouseEvent
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import kCGEventMouseMoved
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseUp
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import kCGHIDEventTap

def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)

def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);

def mouseclick(posx,posy):
#mouseEvent(kCGEventMouseMoved, posx,posy); #uncomment this line if you want to force the mouse to MOVE to the click location first (i found it was not necesary).
mouseEvent(kCGEventLeftMouseDown, posx,posy);
mouseEvent(kCGEventLeftMouseUp, posx,posy);

time.sleep(delay);
mouseclick(xclick, yclick);

print "done."


FWIW, you can replace all the Quartz.CoreGraphics imports with one: from Quartz.CoreGraphics import *

Also, you can place this within a Bash script by placiing it between the block: python <<-END and END (and you can then delete some of the code, i.e. import sys)

Nov 25, 2013 6:48 AM in response to M1hail

The following will move and file in the upper left of the screen (position 40, 60) down an bit (to position 60, 300)


#!/bin/bash

python <<-END
import time
from Quartz.CoreGraphics import *
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); 
# Save current mouse position
currentpos=CGEventGetLocation(ourEvent); 
# move mouse to upper left of screen
mouseclickdn(40, 60);
# drag icon to new location
mousedrag(60, 300);
# release mouse
mouseclickup(60, 300);
# necessary delay
time.sleep(1);
# return mouse to start positon
mouseclickdn(int(currentpos.x),int(currentpos.y)); 
END


See also:

http://developer.apple.com/mac/library/documentation/Carbon/Reference/QuartzEven tServicesRef/Reference/reference.html

http://developer.apple.com/graphicsimaging/pythonandquartz.html

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.

Mouse Move shell app

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