hey,
How do I get the active connection from System Preferences or wherever else has it without using UI scripting?
You parse out the connection shown in the return from:
set activeConnection to (do shell script "ifconfig")
Without arguments, ifconfig shows all possible connections with the last part of each being a status line. You want the one with Status: Active at the end.
oh, thank you… wow, that was exactly what I was looking for! I’ve never used ‘ifconfig’… was it in a relatively new update?
by the way, the output shows the ‘active’ state of each connection, but does it differentiate ‘Connected’ (the green light in System Prefs) vs 'Self Assigned IP Address (the yellow light in System Prefs)?
nvm, I got it… thanks though
ifconfig is an old unix tool from way back originally part of an early 1990s BSD Unix.
I use:
do shell script "netstat -i | grep -v ':' | grep en | awk '{print $1, $4}'"
To return the active ethernet port and network ip. So long as this ip is within my subnet range, I know this is DHCP assigned - green light. (Any other “strange” ip would suggest a self assigned address - amber light!!)
This will obviously only work for wired connections, but I’m sure you could also ‘grep’ out any wireless ones too!