0

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

2
  • 1
    What do you have so far?
    – Ruskes
    Commented Dec 1, 2014 at 17:44
  • To be honest, anything
    – SimoPiersi
    Commented Dec 4, 2014 at 19:07

1 Answer 1

2

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)
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .