Mouse move relative to TOP RIGHT of window?

Hi folks.

This is my first post to Mac Scripter. I’m a very new applescript writer and am pleased to find a healthy community around this topic.

I just downloaded the extra Suites addon so that I can do mouse movements within a GUI. However, I’ve noticed that movements are all relative to the top left of the entire screen. Is there an (easy) way to make mouse coordinates relative to the top right or top left of a specific window?

I understand that the hard way would be to calculate the window size and window position relative to the entire screen and then calculate the correct mouse coordinates that way. But if there’s an easier way or if there’s already function to do that, I’d love to know!

thanks so much!


Well, actually, it’s quite simple.

Bounds of a window are presented as {x top left, y top left, x bottom right, y bottom right}.

Since the window is a rectangle, this works out with a little bit of thought.

Since the y coordinate of the top left is the same as the y coordinate of the top right, we can use this to get the vertical position of the top right of the window. And, of course, use the x coordinate of the bottom right to get x’s position:

tell application "Safari"
set myBounds to the bounds of window 1
set UpperRight to {item 3 of myBounds, item 2 of myBounds}
end tell
--Uncomment this line to make the area clickable
--set item 1 of UpperRight to ((item 1 of UpperRight) - 2)
tell application "Extra Suites"
ES move mouse UpperRight
end tell

However, due to the fact that the windows are not rectangles, and have a very subtle curve to the upper corners, when you click on the supposed upper right, you miss and click the application behind them. So, by subtracting 2 pixels from either coordinate (I chose x), you can make it clickable. Be sure to uncomment that line if you want this to happen.

Hope it helps,


Thanks Superscripter.

I totally see where you’re going with this. I should have made my my question more clear, but I wanted to click on an object INSIDE the window that is always at the same position relative to the top right of the window - even if the window is resized. example: the object is 100,300 from the top right corner.

To do this would I add a couple lines like the following:

set clicklocation to {Item 1 of UpperRight - 100, Item 2 of UpperRight - 300}

tell application "Extra Suites"
ES move mouse clicklocation
end tell

thanks again Superscripter. i’ll give it a shot when I get a chance!


I do know that every window has a view inside it with the contents of the window, but I’m not really sure how to access that.

If we could figure out a way to “talk” to the content view of the window, we could get it’s bounds and work from there. Unfortunately, I’ve never done any GUI scripting before.

This is just a theory, but I think it would work.

If anyone knows how to access this view, please post it here.