Can’t Turn *OFF* Bluetooth on Mac OS X – FIXED

Before continuing, remember the back up your data and I’m not responsible for any loss of data or damage to your computer.

[Jump to solution]

This was bugging me for quite some time, and although there are numerous posts on the web regarding this issue, nothing worked for me.

The problem I was having, was that Bluetooth was on, and couldn’t be turned off. In Bluetooth preferences in System Preferences the “Turn Bluetooth Off” button was greyed out and not selectable, and in the menu bar (sometimes called status bar), the option wasn’t there at all. Below are some screenshots of how it should look when everything’s working okay:

This is how it SHOULD look.
This is how it SHOULD look.
Turn Bluetooth Off didn't exist for such a long time :(
Turn Bluetooth Off didn’t exist for such a long time 🙁

 

This problem persisted through OS X 10.9 Mavericks to OS X 10.10 Yosemite, so at first I was concerned there was a problem with the Bluetooth radio in my computer.

As I say, there are plenty of posts on the web which come up when you search “can’t turn off bluetooth Mac“, and apparent fixes range from resetting the SMC, resetting PRAM, reinstalling kexts and changing .plist files, but nothing worked for me. I tried a lot of things.

So how did I fix it? Well, thankfully due to having OS X Yosemite on an external drive (for development testing while it was in beta) I could boot into that and see if Bluetooth worked properly there. Thankfully, it did, and that means that it’s not a problem with the Bluetooth radio in my Mac, rather a problem with my install. So I set about comparing all the Bluetooth related files hidden away I could find.

For some reason, on my faulty OS X install, in  /Library/Preferences/SystemConfiguration/ there was a file called com.apple.Bluetooth. In my working OS X install, this file didn’t exist. It was the only difference I could see, so I deleted it. After a restart, BEHOLD! The option to turn Bluetooth off re-appeared in both System Preferences and the menu bar.

Hopefully this helps others, as I found nothing to do with this on the web anywhere and there still seemed to be some people in forums that couldn’t fix theirs. Maybe this was the issue.

Detect Mac OS X Screen Lock & Unlock With Objective-C

I really couldn’t find very much on Google about how to detect when OS X has it’s screen locked. Screen lock is not the same as the log in window; screen lock is basically just a system overlay that keeps everything running but locked and secure, while on the other hand the log in screen completely logs the user out and kills the session.

Screen lock is a function that can be activated in the Security panel of System Preferences, but also the Keychain menu bar application can lock the screen for you, or you can press ctrl+shift+eject/power.

I finally stumbled upon this answer on StackOverflow, and in case that link ever dies I thought I would add it here too.

In your .m file you’ll need to set up a  NSDistributedNotificationCenter which listens for screen locked notifications:

And then of course implement the two selectors: