Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm trying to press a button in TeamSpeak using applescript, here is my code:

tell application "TeamSpeak 3 Client" to activate
tell application "System Events"
    tell process "TeamSpeak 3"
        click menu item "Connect" of menu "Connections" of menu bar 1
        delay 2
        click button "Connect"
    end tell
end tell

and here is an image of me hovering over the button in accessibility inspector

Accessibility Inspector inspecting a push button

All I want to be able to do is figure out how to push my button using the information given to me in Accessibility Inspector, but with my code I get the error "System Events got an error: Can’t get button "Connect" of process "TeamSpeak 3"." Here is a screenshot of the window the button is directly inside:

enter image description here

share|improve this question
add comment

1 Answer

You also need to specify the parent objects.

activate application "TeamSpeak 3 Client"
tell application "System Events" to tell process "TeamSpeak 3"
    click menu item "Connect" of menu "Connections" of menu bar 1
    click button "Connect" of window 1 of window 1
end tell
share|improve this answer
1  
Thanks so much for your help! How do you know what window 1 is and menu bar 1 though, for instance, how do you know it's 1 when it could be window 2? Does it say so in the inspector? –  user309641 Jun 4 '12 at 18:33
    
No, but you just have to guess (or run UI elements of window 1, UI elements of window 1 of window 1, etc). –  Lauri Ranta Jun 4 '12 at 18:43
    
@user309641 If you know the title of the window you want to click the button in, you can loop through all the windows until you find the one with the correct title. –  CajunLuke Jun 4 '12 at 19:14
    
@CajunLuke really? I'd love to learn how to do something like that. I'm going to need to start learning more about AppleScript! –  user309641 Jun 5 '12 at 1:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.