network connection

hi

how do I to connect/disconnect and reveal an existing connection ?
I tried with system events, but with poor results.

tell application "System Events"
	set dd to current location of network preferences
	set d to properties of dd
	if connected of location id "5F120419-0B08-5128-AE9D-3F3W6D416C42" of network preferences is false then beep
end tell

You can get and set the “current location” to switch locations. A location does not have a “connected” property. You can do something like this to check your connection.

set currentIP to IPv4 address of (get system info)
if (currentIP does not start with "169") then
	display dialog "I have a connection"
else
	display dialog "I do not have a connection"
end if

And if the script doesn’t help, you can check your connection by trying to ping a website.

regulus6633,
thanks! that works fine. nice one.

before, i tried to use “system events”, for some reasons

These commands are nice; i played around with these, with little success. Maybe they are deprecated…

The shell command networksetup can do a lot of those thing for your.

do shell script "networksetup -printcommands" --will list all available commands
do shell script "networksetup -getairportnetwork Airport" -- get network name where device 'Airport' is connected with

There are a lot of useful commands in networkSetup you can control your airport.

DJ Bazzie Wazzie,

i tried a lot of commands, unfortunately with zero results… :rolleyes:

--do shell script "networksetup -listnetworkserviceorder" -- on"
do shell script "networksetup -setftpproxystate NOKIAMobile-Modem on"

and now i’m not wiser than before. I mean, nice list of commands, but where is the connect-disconnect command?
(i read the entire man entry)
btw, using networksetup requires often admin privileges to work, tats irksome)

Hi,

the dictionary says, the argument of connect is a configuration or a service, not a location

thats absolutely correct, i was only confused between the terms. In the meantime i tried to call configuration and services, or shell commands too. Without success. I miss something…

tell application "System Events"
	get properties of network preferences
	--connect configuration "standart" of network preferences
end tell

(*
{class:network preferences object, current location:location id "B3C899B7-3907-4657-9017-38EF1048D2BE" of network preferences of application "System Events"}
*)

this is an example to connect to a VPN service

tell application "System Events"
	tell network preferences
		tell current location
			set VPNservice to a reference to (first service whose kind is 11)
			if exists VPNservice then connect VPNservice
		end tell
	end tell
end tell

Hi stefan
thanks.

i wrote in the meantime:

tell service of network preferences
		set dd to length of items in (get properties)
		repeat with i from 1 to dd
			set it1 to item i of (get properties)
			set nm to name of it1
			if nm = "XXXX Mobile" then
				set get_interf to it1
				set mid to id of it1
				connect mid
				exit repeat
			end if
		end repeat
	end tell

normally i use to omit tell statements, to accelerate scripts. I’ll take note of it.