DaveHope.co.uk

OSX Click the mouse via code

A few weeks ago I needed to be able to click the mouse via code on my MacBook. After some digging I came across this article, which provided some useful basic code.

I quickly got fed up of having to work out the screen coordinates so have extended the application to use the current coordinates of the mouse. Here’s the code.

// File:
// click.m
//
// Compile with:
// gcc -o click click.m -framework ApplicationServices -framework Foundation -framework AppKit
//
// Usage:
// ./click -x pixels -y pixels -clicks Number Of Clicks - interval wait between clicks
// At the given coordinates it will click and release.

#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>

int main(int argc, char *argv[])
{
NSAutoreleasePool *pool    = [[NSAutoreleasePool alloc] init];
NSUserDefaults *args    = [NSUserDefaults standardUserDefaults];

// Wait 5 seconds before getting the mouse location, give
// the user a chance.
sleep(5);

// Grabs command line arguments -x, -y, -clicks, -interval.
// If not set, it'll use the current mouse location for coordinates
// and 1 for the click count and interval.
int x        = [args integerForKey:@"x"];
int y        = [args integerForKey:@"y"];
int clicks    =    [args integerForKey:@"clicks"];
int interval=    [args integerForKey:@"interval"];
if (x == 0 || y == 0)
{

CGEventRef ourEvent = CGEventCreate(NULL);
CGPoint ourLoc = CGEventGetLocation(ourEvent);

x = ourLoc.x;
y = ourLoc.y;

}
if (clicks == 0)
{
clicks = 1;
}
if (interval == 0)
{
interval = 1;
}

// The data structure CGPoint represents a point in a two-dimensional
// coordinate system.  Here, X and Y distance from upper left, in pixels.
CGPoint pt;
pt.x    = x;
pt.y    = y;

// This is where the magic happens.  See CGRemoteOperation.h for details.
//
// CGPostMouseEvent( CGPoint        mouseCursorPosition,
//                   boolean_t      updateMouseCursorPosition,
//                   CGButtonCount  buttonCount,
//                   boolean_t      mouseButtonDown, ... )
//
// So, we feed coordinates to CGPostMouseEvent, put the mouse there,
// then click and release.
//
int i = 0;
for (i = 0; i < clicks; i++ )
{
CGPostMouseEvent( pt, 1, 1, 1 );
CGPostMouseEvent( pt, 1, 1, 0 );

// Wait interval.
sleep (interval);
}

[pool release];
return 0;
}

You’ll need XCode installed to build it (if you’re desperate for a binary, drop me an e-mail). You can then run with -clicks 375 -interval 4, you then have 5 seconds to place your mouse on the area of the screen where it’ll click.

 

VMware Announces First Open Source Virtual Desktop Client

According to Yahoo Finance, VMWare are releasing an open source client named “VMware View Open Client”.

VMware’s vClient Initiative is to deliver universal clients, desktops that follow users whilst providing a rich personalized experience that is secure, cost-effective and easy for IT to manage.

VMware View Open Client is licensed under the LGPL v 2.1 and can be downloaded from http://code.google.com/p/vmware-view-open-client/. The current release (2.1.1) has been tested with SUSE Linux Enterprise Thin Client (SLETC) and Debian 4.0r3. Lets hope there’s a Mac client just round the corner too!

 

IRIS PAYE-Master password

At work we’re in the process of migrating data from IRIS PAYE-Master over to our Sage accounting package to standardize payroll across our different offices.

We called Sage asking if it was possible to import the data direct and were told that unfortunately that was not going to be possible.

After some investigation it turns out PAYE-Master stores its information in an access database (PM001.DTA).

Renaming PM001.DTA to PM001.MDB and opening in access prompted for a password, but not our PAYE-Master password. I assumed that the database password was going to be derived from our PAYE-Master password so called IRIS and asked them for it (telling them I was going to develop an in house application which interfaced with PAYE-Master).

IRIS, in no uncertain terms said that they could not give out the password as it was the same for all customers.

Hang on a moment, that means that assuming you can get access to the physical data (PM001.DTA) you could view all the payroll information in PAYE-Master if you know this password.

After some disassembly, the password to every PM001.DTA file is Ziueli. Sorry IRIS.