AppleScript to identify the current status of Network Connection

applescriptautomatorNetworkwifi

What is the AppleScript to identify the current status of MacBook Pro's network connection (Yosemite 10.10.3)

  1. Connected via Iphone USB on/off (Hotspotting to Iphone)
  2. Connected via WIFI ON on/off
  3. Connected via Ethernet on/off
  4. No Connection

I want to add this condition check into my Automator Workflow, so workflows run similar to many of the IOS Apps that have the setting "do not send files / do not download unless connected to WIFI"

Best Answer

If you have Network menu bar item/icon in top right menu bar. You can do:

tell application "System Events" to tell process "SystemUIServer"
    value of attribute "AXDescription" of menu bar items of menu bar 1
end tell

To get connection status. For example:

{"Wi-Fi, four of four bars, with WiFiNetworkName.", "Battery: Charged ", "Clock"}

Then you can parse the string/list to check if a certain word is present.