Gui Scripting - Network

Hi Folks,

I have written a Program which sets up a device, adds a modemscript to this device (also username,…) - this works really fine, the only problem is that I have to delete the old device (without the settings) before I can add the “new” one…

I now try to delete the old port with gui scripting:


tell application "System Preferences" to activate
tell application "System Events"
	tell application process "System Preferences"
		click menu item "Network" of menu "View" of menu bar 1
		delay 1
		tell window "Network"
			click pop up button 2
			delay 1
			tell menu of pop up button 2
				click menu item "Network Port Configurations"
			end tell
			delay 1
			tell group 1
				tell scroll area of group 1
					if table row of scroll area of group 1 contains "Some device" then
						-- mark this row
						click button "Delete..."
					end if
				end tell
			end tell
		end tell
	end tell
end tell


on my Intel I reach the Point where I can select the Interface (like Airport) - does anyone has a clue how I can select the interface (mark it) and delete then this interface?

Thanks for your time and your help…

Stefan

the path is

app
window
group
scroll
table
row

So this works for me to highlight/select a row (logic removed for navigation to ntwork config)

tell application "System Preferences" to activate
tell application "System Events"
	tell application process "System Preferences"
		tell window "Network"
			tell group 1
				tell scroll area 1
					tell table 1
						select row 3 -- or whichever row you need through the logic I removed =)
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

Try something like this:

tell application "System Preferences"
	activate
	reveal anchor "Network" of pane id "com.apple.preference.network"
end tell

tell application "System Events"
	tell window 1 of process "System Preferences"
		tell pop up button 2
			click
			delay 1
			click menu item "Network Port Configurations" of menu of it
		end tell
		delay 1
		
		set shouldDelete to false
		set rowList to every row of table 1 of scroll area 1 of group 1
		
		repeat with thisRow in rowList
			if (value of text field 1 of thisRow) is "Untitled" then
				set selected of thisRow to true
				set shouldDelete to true
				exit repeat
			end if
		end repeat
		
		if shouldDelete then
			click button "Delete." of group 1
			delay 1
			click button "Delete" of sheet 1
		end if
	end tell
end tell

Note that the buttons uses an ellipsis (not three periods). You can type an ellipsis by pressing Option+Semicolon (on my US keyboard, at least), or by using “Special Characters.” in most Edit menus.

Hi Bruce, hi James,

thanks a lot for your help! It works great - now I have only to close the application, then I am finished…


--will be done with:

ignoring application responses
tell application "System Preferences" to quit
end ignoring


Best Regards,

Stefan