Reputation: 33356
I've got a few Java based applications that appear to be using (at some level) native windows, complete with the familiar window management buttons and even fullscreen mode buttons. However, I can't seem to access these windows from AppleScript using traditional means. Is there a way to do this?
Currently I have an existing script that works fine on native cocoa apps, but when it tries to access windows for a Java application, it doesn't find any (counting the number of windows will come back 0).
Take IntelliJ IDEA as a concrete example. How might I access the individual windows in order to perform operations on them (say click the minimize or fullscreen buttons)?
Update: Here's a quick example that works on a cocoa application, but not a Java one. In this case I get back the message "every window doesn't understand the count message"
tell application "Safari"
activate
set wins to count of windows
display dialog wins
end tell
Upvotes: 1
Views: 748
Reputation: 19030
The only time you can tell an application to do something like you're trying is if the application is apple-scriptable e.g. does it have an applescript dictionary and does that dictionary have the command you need. I doubt your java application is scriptable so that approach won't work.
You're lucky that you need a window command because system events understands the window command and can often give you the windows of processes. Try this. Just change the name of the process to the process you want and see if it works. If not there's not much else applescript can help you with.
tell application "System Events"
tell process "Safari"
set wins to count of windows
end tell
end tell
display dialog (wins as text)
FYI: if you need to find the name of your application process you can use this...
tell application "System Events" to return name of application processes
Upvotes: 1