Simulate click (or keystroke) in unscriptable background app window

I use an “unscriptable” app (VMware Horizon Client) wherein I want to keep a remote desktop connect “alive.”

This requires clicking or keystroking in its window every 5 minutes or so.

The window has no UI elements; I just want to click at some coordinate in the window, without bringing it to the front.

Is this possible?

I’ve tried stuff like:

tell application "System Events"
	tell application process "vmware-view"
		activate --tried with and without
		keystroke "1"
		click at {100, 100}
		delay 1
		tell window 1
			activate
			keystroke "2"
			click at {100, 100}
		end tell
	end tell
end tell

With or without activate, and whether I tell the app or the window, it’s not working.

(I can grab the props of the window, e.g., size, position)

Or is there a way with JavaScript or python?

  1. While this application is not scriptable, you should use GUI scripting. And GUI scripting works only with frontmost window. So, the answer is: it is not possible without bringing window to the front.
  2. When the window has not UI Elements, you should use some mousetool to click, or some AsObjectiveC code like this:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "ApplicationServices"
use framework "Quartz"
use framework "AppKit"
property updateMouseCursorPosition : true
property buttonCount : 1 -- left mouse button number
property mouseButtonDown : true -- mouse button pressed?

set aPoint to current application's CGPointZero

on setPoint(xPos, yPos)
	set pt to current application's CGPointMake(0, 0)
	set pt to {xPos, yPos}
	return pt
end setPoint

on mouseLeftClick at aPoint
	current application's CGPostMouseEvent(aPoint, updateMouseCursorPosition, buttonCount, mouseButtonDown)
	current application's CGPostMouseEvent(aPoint, updateMouseCursorPosition, buttonCount, not mouseButtonDown)
end mouseLeftClick

tell application "VMware Horizon Client"
	activate
	repeat until window 1 exists
		delay 0.02
	end repeat
end tell

set aPoint to {100, 100}
mouseLeftClick at aPoint -- perform left click and move the cursor to new position
tell application "System Events" to keystroke "1"

set aPoint to {100, 100}
mouseLeftClick at aPoint -- perform left click and move the cursor to new position
tell application "System Events" to keystroke "2"