4

I have an mac application that once opened (in awakeFromNib) shows the user an NSAlert with two buttons, one with "Option1", the other with "Option2". I would like to automate the following flow:

  1. Open the application from the Applications folder.
  2. Choose "Option2" by clicking the button in the NSAlert

So far I've managed to do only the first part:

tell application "Finder"
activate
make new Finder window to startup disk
open application file "My Application.app" of folder "Applications" of startup disk
close Finder window 1
end tell

Can anybody help me with the code? I understand that I can use the System Events commands to catch this click event, but can't manage to find any help online for clicking a button in an NSAlert, and not in a regular Window.

Adam Wright
  • 48,938
  • 12
  • 131
  • 152
MaximD
  • 186
  • 2
  • 6

2 Answers2

0

You might try this...

tell application "My Application" to activate

delay 5

tell application "System Events"
    tell process "My Application"
       click button "option 2" of window 1
    end
end
regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • Nope, sorry i get the following error: System Events got an error: Can’t get window 1 of process "My Application". Invalid index. – MaximD May 30 '11 at 08:26
  • 1
    Well what can you get? Is it a sheet or window that is displayed? Without knowing the application you'll have to do some investigating yourself. I'm only showing you a basic approach. You have to figure out what kind of thing the button is on and then click it somehow. And if it's the default button (highlighted blue) then you're lucky and you can just "keystroke return" because that will press the default button if it's frontmost. – regulus6633 May 30 '11 at 16:24
0

How many windows do you have open? It's probably getting confused.

If you need to the program UI Browser can generally find the proper terms for GUI Scripting. I'm not sure it's worth buying just for this but you can run the program in demo mode for a month and use it to find the proper terms.

http://pfiddlesoft.com/uibrowser/

Clark
  • 833
  • 4
  • 6