How can I write an Apple Script in order to check if bluetooth and ethernet are on or off? I'm trying to write a little script in order to check whether or not bluetooth is on and whether or not an ethernet cable is plugged in. I searched the System Preference dictionary built in the app but it seems there isn't any help about checking if the bluetooth is on or off.

Can anyone help me?
Best Regards
Simone Piersigilli
This can by done by involving some command-line foo:

set btStatus to do shell script "/usr/local/bin/blueutil power"
set enStatus to do shell script "ifconfig en0 | grep 'status' | cut -d ':' -f 2 | tr -d ' '"

if btStatus = "1" then
    set bluetoothEnabled to true
    log "Bluetooth is enabled"
else if btStatus = "0" then
    set bluetoothEnabled to false
    log "Bluetooth is disabled"
else
    log "Could not determine Bluetooth status"
end if

if enStatus = "active" then
    set ethernetEnabled to true
    log "Ethernet is enabled"
else if enStatus = "inactive" then
    set ethernetEnabled to false
    log "Ethernet is disabled"
else
    log "Could not determine Ethernet status"
end if


The interesting parts are the first two lines.

Please note:


This requires blueutil to be installed (you can install it easily using Homebrew)
You might need to change en0 to the interface you want to check (you can get a list of all interfaces by entering ifconfig into a terminal)
You might need to change the path to blueutil (depending how you installed it)