Jump to content

Bluetooth and wifi toggle


Recommended Posts

Here's a little workflow for toggling bluetooth and wifi.

Basic usage:
bt - toggle bluetooth, see status

bluetooth - toggle bluetooth
wifi - toggle wifi

Download: https://www.dropbox.com/s/xcka1l6pxt8ibsn/BT%20%26%20Wifi%20Toggle.alfredworkflow (as of 08/03/2014)

 

Important update: The latest version of this workflow uses a new (unofficial) version of blueutil which is a copy of the original source code, only rewritten and compiled (by me) for the latest OS X, that is for the OS X 10.10 beta, too. I am a little worried that by having it compiled for the beta, it won't work for 10.9 and lower but I hope there won't be a problem. If there is, please tell me and I will release a version with the original blueutil.

Using: custom version of blueutil (http://www.frederikseiffert.de/blueutil/)

Edited by Fasand
Link to comment
For me the bluetooth toggle doesn't work. It just opens System Preferences/Bluetooth.

 

That's weird. For me, it works ok (doesn't open System Preferences). It should actually close them if they're open. It even connects my magic mouse after the second toggle.

 

What OS do you have? (Lion/Mountain Lion)

 

Possibly, if you wait a while, it could work, but if it opens System Prefs there is probably a different problem.

 

( Btw thanks for reply ;) )

Link to comment
I'm on 10.8.2

 

I did have a little problem with the disconnection of devices, i.e. when I have my magic mouse connected, the system preferences toggle triggered by applescript doesn't do exactly what I want it to do, so it's actually ran twice just so that it works.

 

This however does not explain why it opens up your system prefs.

 

I am sorry, but I really don't know what the problem is, as I even have the same OS version and it looks like it's acting completely different for you.

 

If I figure it out, I will post it here.

Link to comment

Good start here, but we need a couple of tweaks.

 

I'm on 10.8.2, with updates, etc.  I'm on this last August's MBP 13".  The Airport is en1 on it (en0 is the hardline). I hard-coded it in mine for the time-being. I'm really new to Applescript, so I haven't worked out a good scheme to look it up reliably or I'd offer it here.

The bluetooth toggle was doing fine at turning it on—but the thing about turning it off, the second "if" evaluation would always find the power off and turn it on.  So if off, it was turning it on. If on, it was turning it off, then on.   I replaced the two if blocks with "click A" and it's working well now.

Link to comment

When I was testing it, I found that if there wasn't the second click, my mouse wouldn't connect again and it caused problems. With the other if, it works with my mouse, however more like a bluetooth "turn off and on" than a real toggle.

 

As for the en1 problem, I understand as I thought I had en1, too at first, but then I found otherwise. I have 10.8.2 on a 2012 MBA, so I have no idea why it's different, but I guess it's not that big of a problem (mostly because there are much better extensions that include wifi toggle).

 

Essentially, I created this mostly so that I don't have to go to the menu bar and connect my mouse, so using this, I just write a short command twice. That is why it doesn't work that well for others and why the wifi toggle is set for en0. I am lazy. Please take this more as a workflow to work with and make it yours, not a good, publicly distributable workflow. I posted it only because I haven't found any similar and because I hoped that someone would get the idea to make something similar, but better and working ;).

 

To end this pointless self-letter, good luck with this semi-working workflow  ;).

Link to comment

Hi,

 

i changed the wifi apple script to

on alfred_script(q)
	set wifi to (do shell script "networksetup -listallhardwareports | grep -A 1 Wi-Fi | tail -n 1 | cut -b 9-12")
	if (offset of "On" in (do shell script "networksetup -getairportpower " & wifi & " ")) > 0 then
		do shell script "networksetup -setairportpower " & wifi & " off"
	else
		do shell script "networksetup -setairportpower " & wifi & " on"
	end if
end alfred_script

 

I defined the variable wifi which will grep the wifi interface from networksetup so it shouldn't matter wether your wifi card is en0,en1...en20 :)

 

I could only test it on my machine so i am not 100% sure it'll work for everyone.

 

Mike

Link to comment
  • 2 weeks later...

Not working for me either. I just get this message:

 

"You cannot control your computer if you turn Bluetooth off at this time as you would lose your input devices." 

 

I haven't encountered this at all, but from what I read I suspect you have the Magic Trackpad. If yes, than this is a system issue, completely unknown to me and I'm sorry, but if Apple hasn't resolved this in quite a long time, I have no chance/idea...

 

If you are not using the Magic Trackpad, than there is a different problem that I am trying to solve right now. If I find something out, I will let you and everybody know.

Link to comment

This one isn't working for me. Not sure what the problem is. The wifi toggle works but the bluetooth does not. Gives me a "Failed to toggle bluetooth" error with my bluetooth connections pane displayed. 

 

Running brand new MBP with Mountain Lion.

 

Some people before you probably encountered the same problem, yet I still don't really know what the problem is...

 

The worst thing about this is that it works for most people, but for some people with same hardware doesn't  :)...

 

I added a line that should write out the error when it occurs, so please update the workflow from the link below and when the error occurs, reply here what it says, which could possibly lead to a solution.

 

Download: http://d.pr/f/5pM0

Link to comment

This one isn't working for me. Not sure what the problem is. The wifi toggle works but the bluetooth does not. Gives me a "Failed to toggle bluetooth" error with my bluetooth connections pane displayed. 

 

Running brand new MBP with Mountain Lion.

 

 

Not working for me either. I just get this message:

 

"You cannot control your computer if you turn Bluetooth off at this time as you would lose your input devices." 

 

 

For me the bluetooth toggle doesn't work. It just opens System Preferences/Bluetooth.

 

I did not find a solution on how to alter the AppleScript for it to work, but I found a nice little (old) utility for toggling bluetooth which has thankfully nothing to do with AppleScript and I added it into my workflow.

 

If you are still interested, here is the link to download: http://d.pr/f/9YZR

 

If this doesn't work (it should!), I really don't know.

Link to comment

I did not find a solution on how to alter the AppleScript for it to work, but I found a nice little (old) utility for toggling bluetooth which has thankfully nothing to do with AppleScript and I added it into my workflow.

 

If you are still interested, here is the link to download: http://d.pr/f/9YZR

 

If this doesn't work (it should!), I really don't know.

 

I am using a Magic trackpad. This one works for me though. Thanks!

Link to comment

I did not find a solution on how to alter the AppleScript for it to work, but I found a nice little (old) utility for toggling bluetooth which has thankfully nothing to do with AppleScript and I added it into my workflow.

 

If you are still interested, here is the link to download: http://d.pr/f/9YZR

 

If this doesn't work (it should!), I really don't know.

 

 

Thanks very much for the update. I use a magic mouse not a magic trackpad, but this one seems to work flawlessly. Appreciate the work.

Link to comment
  • 1 month later...
  • 2 weeks later...

Thank you for the workflow, but it always left the SysPref window open after I used it and since I don't know/want to learn AppleScript, I reused your icons and made it in bash script.

 

Only problem is that for the Bluetooth toggle, there is no easy way to do this with vanilla osx. You have to install a small utility called blueutil, that you can get here: http://www.frederikseiffert.de/blueutil/

 

The extension is here: http://cl.ly/2Q3v191C0G37

Edited by MetalRufflez
Link to comment

Thank you for the workflow, but it always left the SysPref window open after I used it and since I don't know/want to learn AppleScript, I reused your icons and made it in bash script.

Only problem is that for the Bluetooth toggle, there is no easy way to do this with vanilla osx. You have to install a small utility called blueutil, that you can get here: http://www.frederikseiffert.de/blueutil/

The extension is here: http://cl.ly/2Q3v191C0G37

Update the workflow using the link in the first post and look inside the workflow's folder :).

I already stopped using the AppleScript way as it sucked and caused problems. Now it's using blueutil and works perfectly.

Link to comment
  • 5 months later...

Is anyone having trouble with this script after upgrading to Mavericks?

 

Since I upgraded last week, I can no longer use this workflow without receiving an error message "Failed to Toggle Bluetooth".

 

In accessibility, Alfred 2 has the permissions to control my computer and I attempted to install the linked bt utility but received an error message /Volumes/blueutil/Install.command ; exit;

0:109: execution error: cp: directory /usr/local/bin does not exist (1)

logout

 
Thoughts?
Link to comment

 

Is anyone having trouble with this script after upgrading to Mavericks?

 

Since I upgraded last week, I can no longer use this workflow without receiving an error message "Failed to Toggle Bluetooth".

 

In accessibility, Alfred 2 has the permissions to control my computer and I attempted to install the linked bt utility but received an error message /Volumes/blueutil/Install.command ; exit;

0:109: execution error: cp: directory /usr/local/bin does not exist (1)

logout

 
Thoughts?

 

 

That's weird. I upgraded to Mavericks and everything works fine, maybe try to download the workflow again (http://d.pr/f/ybMT).

 

As for installing the utility, the error simply says that your /usr/local/bin doesn't exist, so try creating it: mkdir /usr/local/bin and installing it again, not sure however if that might help.

 

If anything works (or doesn't) be sure to tell me  ;).

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...