Close Window Shortcut in a Java Application

I have a java application that of course does correspond to basic Mac protocols and behaviour. Does anyone know of a way of creating a keyboard shortcut that would let you close windows. The only way of doing so in the native application is to click on the "x" in the upper left hand corner of each widow.

You could use an Execute AppleScript action with the following code:

tell application "System Events" to click ¬
	button 1 of window 1 of the ¬
	(first process where it is frontmost)

This is provided that the application in question has accessibility.

1 Like

Thanks for that. Unfortunately it doesn't seem to work. It doesn't seem to recognise the java app as a bone fide application. And strangely enough open the apps help page in Safari. Weird stuff!

This works for me in ThinkOrSwim, which I believe is a Java app:


The Java app should be frontmost when you trigger this macro.

I finally found a solution to this. Unfortunately, none of the suggestions above worked for me. However this simple one does: