0

I'm writing a script for an application that does not support scripting. This is a proprietary app that I'm stuck with, so there's no alternative for me. The problem I'm having is this app does not respond well to "activate". When I'm activating it in an applescript, it brings its main window to the foreground, but the window is still not fully active (e.g. the Close/Minimize/Fullscreen buttons are grey, the shadow around the window is faint, etc). I have to click on it or cmd-tab twice to get it to activate. The application has some logic in it that prevents it to start functioning until the window is truly active, so I have to make the window truly active.

The workaround I'm using right now is to make the script press cmd-tab twice.

tell application "MyApp" to activate
key down command
keystroke tab
key up command
key down command
keystroke tab
key up command

I was wondering if there's a more elegant solution to make the app truly active.

1

The alternative is to activate your app through Dock:

tell application "System Events" to click UI element "MyAPP" of list 1 of application process "Dock"

The way I got here is to use Automator's record feature and copy the steps" and paste them in Script Editor. It translates them to AppleScript.

| improve this answer | |
  • That does it! I've removed all the automator candy and reduced this down to this: tell application "System Events" to click UI element "MyAPP" of list 1 of application process "Dock" – Zozozi Mar 17 at 17:44
0

If the application is already running then try this:

tell application "System Events" to set frontmost of process "NameOfApp" to true

| improve this answer | |
  • No dice, the window activates but still is out of focus. – Zozozi Mar 17 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .