So I found the way to click “add new service” with below source code
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.network"
end tell
tell application "System Events"
tell process "System Preferences"
click button 5 of window 1
end tell
end tell
but I can find the way to click list menu and the button of popup menu…
the parent element of the popup menu is a sheet.
Try this
property newServiceKind : "Ethernet"
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.network"
end tell
tell application "System Events"
tell process "System Preferences"
tell window 1
click button 5
repeat until exists sheet 1
delay 0.2
end repeat
tell sheet 1
tell pop up button 1
click
pick menu item newServiceKind of menu 1
repeat until its value is newServiceKind
delay 0.2
end repeat
end tell
set value of text field 1 to "new ethernet service"
click button "Create"
end tell
end tell
end tell
end tell