简体   繁体   中英

Clicking button using Apple Script

I want to add some details to an UI application from an Apple script. But i cannot click the "New" button in UI from script.

tell application "System Events" to tell process "Microsoft Remote Desktop"
    --click button 1 of group 1 of toolbar 1 of window 1
    click button "New" of group 1 of toolbar 1 of window 1
end tell

MSTSC

Accessibility Inspector

在此处输入图片说明

You cannot use "New" for the button's name because the value for the name property of button 1 of group 1 of toolbar 1 of window 1 of application process "Microsoft Remote Desktop" is missing value .

However, the value for the description property is New , so the following example AppleScript code works for me:

activate application "Microsoft Remote Desktop"
delay 1
tell application "System Events" to tell application process "Microsoft Remote Desktop"
    click (every button of group 1 of toolbar 1 of window 1 whose description is "New")
end tell
  • Note that the value of the delay commands may need to be adjusted for your system, and or additional delay commands may or may not be needed. Adjust values of and or add/remove the delay commands as appropriate.

You can use the following example line of code to get the properties of button 1 of group 1 of toolbar 1 of window 1 if Microsoft Remote Desktop is already running with just the main window open:

tell application "System Events" to get properties of button 1 of group 1 of toolbar 1 of window 1 of application process "Microsoft Remote Desktop"

Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways to accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM