Create New Location

Hi Folks,

I try to make some GUI Scripting - but when I try to Create a New Location I see the following problems:


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 1
			click
			delay 1
			click menu item "New Location..." of menu of it
		end tell
		delay 1
	end tell
end tell

Apple Script Error - NSReceiverEvaluationScriptError: 4

It is funny, because the Location “Automatic” can be selected…

Best Regards and thanks for your help…

Stefan

Try using an ellipsis (Option+semicolon on my US keyboard) instead of three periods:

click menu item "New Location." of menu of it

Hi Stefan,

wrong syntax and wrong spelling of the menu item (… are not 3 dots, it’s called horizontal ellipsis ALT-dot on a german keyboard layout)

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 1
			click
			pick menu item "New Location." of menu 1
		end tell
		delay 1
	end tell
end tell

Hi Folks,

this is solving the issue…


tell application "System Events"
	if (name of processes) contains "System Preferences" then tell application "System Preferences" to quit
end tell

delay 1

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
	tell process "System Preferences"
		set frontmost to true
		try
			tell window 1
				click pop up button 1
				tell pop up button 1
					tell menu 1
						click menu item "New Location."
						keystroke "Test"
						delay 3	
					end tell
				end tell
			end tell
		end try
	end tell
end tell


BR

Stefan

Hi Folks,

how can I press the “OK” button?


tell application "System Events"
	if (name of processes) contains "System Preferences" then tell application "System Preferences" to quit
end tell

delay 1

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
	tell process "System Preferences"
		set frontmost to true
		try
			tell window 1
				click pop up button 1
				tell pop up button 1
					tell menu 1
						click menu item "New Location."
						keystroke "Test"
						delay 3
						click button 1 of window 1 --how can I press the button?
					end tell
				end tell
				
			end tell
		end try
	end tell
end tell

Thanks for your help,

Stefan

try this

tell application "System Events"
	if (name of processes) contains "System Preferences" then quit application "System Preferences"
end tell

delay 1

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
	tell process "System Preferences"
		try
			tell window 1
				tell pop up button 1
					click
					click menu item "New Location." of menu 1
				end tell
				repeat until exists sheet 1
					delay 0.5
				end repeat
				tell sheet 1
					keystroke "Test"
					click button "OK" --how can I press the button?
				end tell
			end tell
		end try
	end tell
end tell

Hi Stefan,

I have already tried that - but it is not working…

br,

Stefan

Hm, it works on my machine.
Do you get an error message and in which line?

Hi Stefan,

don´t ask me why, but it looks like that I had some problems with my Network Settings - after a reboot it
is now working…

thanks for your help - and please be prepared - I will have some more questions this evening… :slight_smile:

BR

Stefan

Hi Folks,

what can I do to enter the Provider in the Network Dialup Pane?

what is the name for the first field (Provider)

UI Element Inspector just says that this is a text field…

thanks for any feedback!

Stefan


keystroke "Test" 

tell application "System Events"
	if (name of processes) contains "System Preferences" then quit application "System Preferences"
end tell

delay 1

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
	tell process "System Preferences"
		try
			tell window 1
				
				tell pop up button 1
					click
					click menu item "New Location." of menu 1
				end tell
				repeat until exists sheet 1
					delay 0.5
				end repeat
				tell sheet 1
					keystroke "Test"
					click button "OK" --how can I press the button?
				end tell
				delay 1
				tell pop up button 2
					click
					delay 0.5
					click (1st menu item of menu 1 whose name contains "Ethernet")
				end tell
			end tell
			tell application "System Preferences" to reveal anchor "PPPoE" of pane id "com.apple.preference.network"
			tell group 1 of tab group 1 of group 1 of window 1
				tell checkbox "Connect using PPPoE"
					if value is 0 then click
				end tell
				set value of text field 4 to "test"
			end tell
		end try
	end tell
end tell

Hi Stefan,

thanks a lot - but how can I switch the tabs?

click radio button "Modem"  of tab group 1 of group 1 of window "System Preferences"

is not presenting any results…

Best regards,

Stefan

If you want to access the Modem tab, use this


...
tell pop up button 2
					click
					delay 0.5
					click (1st menu item of menu 1 whose name contains "Modem")
				end tell
			end tell
			tell application "System Preferences" to reveal anchor "PPP" of pane id "com.apple.preference.network"
			tell group 1 of tab group 1 of group 1 of window 1
				set value of text field 4 to "test"
			end tell
		end try
	end tell
end tell
...

switching a tab (called anchor) will be executed by

tell application "System Preferences" to reveal anchor "PPP" of pane id "com.apple.preference.network"

Hi Stefan,

it is pretty funny, when I use this code


set modem to "Web'n'walk Box compact"

tell application "System Events"
	if (name of processes) contains "System Preferences" then quit application "System Preferences"
end tell

delay 1

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
	tell process "System Preferences"
		try
			tell window 1
				tell pop up button 1
					click
					click menu item "New Location." of menu 1
				end tell
				repeat until exists sheet 1
					delay 0.5
				end repeat
				tell sheet 1
					keystroke "T-Mobile"
					click button "OK" --how can I press the button?
				end tell
				
				tell pop up button 2
					click
					if modem is "Web'n'walk Box compact" then
						click menu item "HUAWEI Mobile" of menu 1
						delay 0.5
						display dialog "hier"
						tell application "System Preferences" to reveal anchor "Modem" of pane id "com.apple.preference.network"
						click
					end if
				end tell
			end tell
		end try
	end tell
end tell

then the following is happening:

display dialog “hier” is correct - the script is standing on the Huawei Mobile on the PPP tab!

tell application “System …” is jumping to the “Internal Modem” - do you know why this happens?

BR and Thanks a lot!

Stefan

Hi Stefan,

I guess that the reveal anchor command can only access the built-in tabs (anchors) of the PrefPane,
or the modem tab of your HUAWEI Modem has a different name
To check it, run this script

tell application "System Preferences"
	get name of anchors of pane "com.apple.preference.network"
end tell

this results a list of the names of all anchors.

Hi Stefan,

you were absolut right - it is not there…

{“Ethernet”, “Modem”, “Proxies”, “AppleTalk”, “TCP/IP”, “Network”, “PPP”, “BlueTooth”, “PPPoE”, “AirPort”}

BR and thanks a lot!

Stefan

Finally I got the correct code for

: creating a new location
: entering an existing device
: entering a new Provider Name
: switch to the Modem Tab and select a Modem Script
: Apply the Settings
: quiting the Application


set modem to "Web'n'walk Box compact/II/Card plus"

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell

tell application "System Events"
	tell process "System Preferences"
		tell window 1
			
			tell pop up button 1
				click
				click menu item "New Location." of menu 1
				delay 0.5
			end tell
			delay 1
			tell sheet 1
				keystroke "T-Mobile"
				click button "OK"
				delay 0.5
			end tell
			if modem is "Web'n'walk Box compact/II/Card plus" then
				tell pop up button 2
					click
					click (first menu item of menu 1 whose name contains "HUAWEI Mobile")
				end tell
				
				tell tab group 1 of group 1
					delay 0.5
					set value of text field 4 of group 1 to "T-Mobile"
					delay 0.5
					confirm text field 4 of group 1
					delay 0.5
					click radio button "Modem"
					delay 0.5
				end tell
				
				tell pop up button 1 of group 1 of tab group 1 of group 1
					click
					delay 0.5
					click menu item "T-Mobile HSDPA" of menu 1
					delay 0.5
				end tell
				click button "Apply Now"
			else if modem is "Web'n'walk Card express" then
				display dialog "something"
			else if modem is "Web'n'walk Card compact/II" then
				display dialog "something"
			end if
		end tell
		
	end tell
end tell

quit application "System Preferences"