Java on OS X - A free Mac/Java application to get the mouse cursor location and color

As I go through some old applications I wrote for various purposes, but never released, I thought I'd share the source code for a Java program that you can use to get the x/y coordinates or the mouse cursor (pointer) and RGB value of the pixel at that location. I've used this application for various reasons, including determining the location of something on screen, determining the width or height between two points, or getting the RGB value of a pixel on screen.

I'm sharing the source code for this "Java on Mac OS X" application, including the entire project -- which includes the Ant build script I use to build Java applications into native Mac OS X applications. This is all available in the "Download" section below.

Using the XYLocator

Using the XYLocator is simple. Here's how to use it:

  • Start the app, which will display the dialog shown below.
  • Click the "Get X/Y" button.
  • The dialog disappears, the app takes a picture of your desktop, and then displays that picture as an image.
  • You then click on that image to get the X/Y coordinates and RGB value of the cursor position.
  • When you click, the image goes away, and the application window comes back, now displaying the X/Y position you clicked on, as well as the RGB value at that pixel location. You can get another X/Y coordinate by following the same process, quit the app, minimize it, hide it, whatever.

Here's what the application looks like when you first launch it:

Mac OS X XY Locator - cursor position locator - view at startup

And here's what it looks like after you've clicked a point on screen:

Mac OS X XY Locator - cursor position locator - view after clicking a pixel

Probably the only confusing part about the app is that I need to take a picture of the Desktop, and then display it to you in an image. This is because the program is written in Java, and I don't know any other way to track the cursor location from Java. Once you understand that you're looking at an image, the app is easy to use.

P.S. -- I hope you like the Mac application icon, I made it myself. :)

The XYLocator Mac OS X application

If you just want to download the XYLocator as a Mac OS X application, you can use this link:

Once you've downloaded this zip file, just double-click it to open it, and then you can install this just like any other Mac OS X application.

The XYLocator source code

If you'd rather download the XYLocator Java source code, you can download it from this link:

The current source code only works on Mac OS X systems, but if I get a bunch of requests to get this working on Windows or Linux, I'll be glad to put some time into it. Or, since you can get the source code here, you can get this working on Linux or Windows, and then send me the improved version. :)

P.S. - The source code is pretty crappy, but hey, I initially wrote this as an experiment nearly 10 years ago, and I was in a hurry, and atm, I don't feel like cleaning it up.

Creating a Mac OS X application from a Java build

One other cool thing about having all the source code for this application is that it demonstrates how to create a native a Mac OS X application from a Java source code application. In fact, it demonstrates quite a few things about the "Java on Mac OS X" build and development process, and that may be as helpful as anything.

XYLocator - summary

I hope my free XYLocator application helps you, either by letting you easily get the X and Y coordinates of stuff on your screen, or by helping you learn about Java, and creating a native Mac OS X application from Java source code.