Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Press a button using Applescript

I've written a very simple script to open an FTP application. In order to complete the action and fully open the application there is a popup window with two buttons; button 1 is dimmed button 2 says connect which is what I want to do. I get no error in my script, but the button is never clicked. It is lightly blinking. If I press the connect button manually, the application completes the action.


Here is my script:

tell application "Yummy FTP"


delay 2



activate


tell application "System Events"


tell process "Yummy FTP"



clickbutton 2 of window 1


end tell


end tell


end tell

What have I missed?

Thanks,

Kathy

Mac Pro, iOS 9

Posted on Dec 29, 2016 11:14 AM

Reply
Question marked as Best reply

Posted on Dec 29, 2016 1:16 PM

Kathy,


In GUI scripting, one needs the Accessibility Inspector from Xcode to determine what UI element hierarchy is present. Dependent solely on the UI designer, one cannot assume that button 2 is the pulsing "Connect" button, or that the window hierarchy is Window 1 => {Button 1, Button 2}. It might be Window 1=> Group 1 => Row 1 => {Button 1, Button 2}. I have listed the buttons in numeric order, but they may not follow this ordering.


I don't have Yummy FTP, but try the following code to see if you can just press a return on that pulsing, default "Connect" button. I have restructured the code the way I normally write GUI scripts, but you retain poetic license.


tell application "System Events"

tell application process "Yummy FTP"

activate

set frontmost to true

-- press return on that pulsing, default "Connect" button. Assumption: That window is present.

tell front window to key code 36

-- tell front window to tell button "Connect" to click

end tell

end tell

3 replies
Question marked as Best reply

Dec 29, 2016 1:16 PM in response to startouchedga

Kathy,


In GUI scripting, one needs the Accessibility Inspector from Xcode to determine what UI element hierarchy is present. Dependent solely on the UI designer, one cannot assume that button 2 is the pulsing "Connect" button, or that the window hierarchy is Window 1 => {Button 1, Button 2}. It might be Window 1=> Group 1 => Row 1 => {Button 1, Button 2}. I have listed the buttons in numeric order, but they may not follow this ordering.


I don't have Yummy FTP, but try the following code to see if you can just press a return on that pulsing, default "Connect" button. I have restructured the code the way I normally write GUI scripts, but you retain poetic license.


tell application "System Events"

tell application process "Yummy FTP"

activate

set frontmost to true

-- press return on that pulsing, default "Connect" button. Assumption: That window is present.

tell front window to key code 36

-- tell front window to tell button "Connect" to click

end tell

end tell

Dec 30, 2016 9:03 AM in response to VikingOSX

Oh my!!! It worked!!! Thank you sooooo much!! I did have to tweak it a bit. Here is what worked:


tell application "Yummy FTP"


delay 2



activate


tell application "System Events"


tell process "Yummy FTP"


set frontmost to true


tell front window to key code 36


end tell


end tell


end tell

Thanks again for all your help!! I hope this is helpful to someone else also!!

Kathy

Press a button using Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.