Turn Wi-Fi / Bluetooth on/off with LaunchBar

Sharing and discussing custom actions for LaunchBar
paradox2222
Posts: 2
Joined: Sat Jan 30, 2010 4:19 pm

Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby paradox2222 » Sat Jan 30, 2010 4:25 pm

Hello, I was wondering if anyone knew of a way to turn wifi and/or bluetooth on or off from launchbar. Could this be done by a service or a script or an actual launchbar command? I don't like having the bluetooth icon in my menubar and I would love for a quick way to deactivate the battery taxing services when I am on the go and need all the power I can get. Thanks in advance!

Dan

m.yellow
Posts: 16
Joined: Sat Jan 02, 2010 4:46 pm

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby m.yellow » Wed Feb 03, 2010 2:52 pm

for bluetooth I have a solution: you can download blueutil (http://www.frederikseiffert.de/blueutil/), install it and then use this script to toggle status

Code: Select all

set bt_status to do shell script "blueutil status"

if bt_status is "Status: on" then
   do shell script "blueutil off"
else
  do shell script "blueutil on"
end if


untested, but should work in that way (maybe you have to change the path to blueutil) ...

jordi
Posts: 12
Joined: Thu Feb 19, 2009 6:43 pm

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby jordi » Tue Feb 16, 2010 12:12 pm

I've written an AppleScript for Airport as well. It includes Growl notification. Probably not the most elegant script, but it works.

Code: Select all

property airportUtil : "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I"

set res to do shell script airportUtil & " -p || exit 0"

if res contains "off" then
   -- Toggle Airport on
   do shell script "networksetup -setairportpower en1 on 2>/dev/null"
   set apStatus to true
else if res contains "on" then
   -- Toggle Airport off
   do shell script "networksetup -setairportpower en1 off 2>/dev/null"
   set apStatus to false
end if

tell application "GrowlHelperApp"
   -- Tell Growl we want to send a notification, use the Airport Utility icon
   register as application ¬
      "Airport AppleScript" all notifications {"Airport Notification"} ¬
      default notifications {"Airport Notification"} ¬
      icon of application "Airport Utility"
   if apStatus is true then
      notify with name ¬
         "Airport Notification" title ¬
         "Airport status" description ¬
         "Airport is now ON." application name "Airport AppleScript"
   else
      notify with name ¬
         "Airport Notification" title ¬
         "Airport status" description ¬
         "Airport is now OFF." application name "Airport AppleScript"
   end if
end tell

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby ptujec » Tue Feb 16, 2010 2:42 pm

Nice! Thx!

macsterdam
Rank 2
Rank 2
Posts: 41
Joined: Thu Nov 16, 2006 5:22 pm

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby macsterdam » Wed Feb 17, 2010 11:49 am

The Wifi script is brilliant - thanks very much!

sjk
Wizard
Wizard
Posts: 315
Joined: Thu Sep 13, 2007 9:46 pm
Location: Eugene
Contact:

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby sjk » Wed Feb 17, 2010 9:34 pm

jordi wrote:Probably not the most elegant script, but it works.

It does assume "en1" is the interface for AirPort. :)

Maybe make that a variable (or property; whatever it's called in AppleScript terminology), like airportUtil is?

Also would be nice if the script was under LaunchBar Scripts.
Last edited by sjk on Fri Mar 12, 2010 7:58 pm, edited 1 time in total.

Conheim
Posts: 12
Joined: Sun Jan 17, 2010 3:46 pm

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby Conheim » Sun Feb 21, 2010 1:09 am

jordi wrote:I've written an AppleScript for Airport as well. It includes Growl notification. Probably not the most elegant script, but it works.


jordi, you are my personal hero for tonight (and most likely every time I’ll use this script). Thank you.

FiXeR
Posts: 5
Joined: Sat Jan 30, 2010 10:52 am

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby FiXeR » Sat May 08, 2010 11:29 pm

UPDATE: now its working :)

Code: Select all

set bt_status to do shell script "/usr/local/bin/blueutil 'status'"

if bt_status is "Status: on" then
   do shell script "/usr/local/bin/blueutil 'off' "
else
   do shell script "/usr/local/bin/blueutil 'on' "
end if


UPDATE 2:
I made similiar Growl notification as with Wifi. Hope you like it.

Code: Select all

set bt_status to do shell script "/usr/local/bin/blueutil 'status'"

if bt_status is "Status: on" then
   do shell script "/usr/local/bin/blueutil 'off' "
else
   do shell script "/usr/local/bin/blueutil 'on' "
end if

tell application "GrowlHelperApp"
   -- Tell Growl we want to send a notification, use the Bluetooth Utility icon
   register as application ¬
      "Bluetooth AppleScript" all notifications {"Bluetooth Notification"} ¬
      default notifications {"Bluetooth Notification"} ¬
      icon of application "Bluetooth File Exchange"
   if bt_status is "Status: off" then
      notify with name ¬
         "Bluetooth Notification" title ¬
         "Bluetooth status" description ¬
         "Bluetooth is now ON." application name "Bluetooth AppleScript"
   else
      notify with name ¬
         "Bluetooth Notification" title ¬
         "Bluetooth status" description ¬
         "Bluetooth is now OFF." application name "Bluetooth AppleScript"
   end if
end tell

smithdwsn
Posts: 2
Joined: Thu May 13, 2010 7:28 pm

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby smithdwsn » Fri May 14, 2010 2:53 pm

Amazing, it works very well and i have just connected with bluetooth and works very nice. No problem of speed and other requirement. Also provides additional utilities for that. I have done some changes in that. By the way, it is the perfect script for turn off and on with launchbar.

FiXeR
Posts: 5
Joined: Sat Jan 30, 2010 10:52 am

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby FiXeR » Sat May 15, 2010 3:04 am

What addditional utilities? What changes? Please share with us :)

daniel_simz
Posts: 1
Joined: Sat May 15, 2010 3:07 am
Location: Madison Road Norridgewock ME 03801
Contact:

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby daniel_simz » Sat May 15, 2010 3:11 am

You're such a genius thanks..it works well and I have no problem with it.

paul7
Posts: 13
Joined: Sat Apr 04, 2009 10:05 pm

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby paul7 » Tue Oct 19, 2010 8:37 am

Brilliant!! Thanks all!

alxndrmlr
Posts: 1
Joined: Tue Jan 11, 2011 11:14 pm

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby alxndrmlr » Tue Jan 11, 2011 11:21 pm

sjk wrote:
jordi wrote:Probably not the most elegant script, but it works.

It does assume "en1" is the interface for AirPort. :)


I just wrote my own script for this today and was notified by @ptujec about this thread so I thought I would share my solution.

Code: Select all

# Toggle Airport Device On/Off
#
# This script will either turn on or off
# your AirPort card based on its current state.

# Fetch the name of your AirPort Device
set airPortDevice to do shell script "/usr/sbin/networksetup -listallhardwareports | awk '{if($3==\"AirPort\"){getline;print}}' | awk '{print $2}'"

# Fetch the current state of the AirPort device
set airPortPower to do shell script ("networksetup -getairportpower " & airPortDevice & " | awk '{print $4}'")

if airPortPower is equal to "on" then
    toggleWifi("off", airPortDevice)
else
    toggleWifi("on", airPortDevice)
end if

on toggleWifi(value, device)
    do shell script ("/usr/sbin/networksetup -setairportpower " & device & " " & value)
end toggleWifi


That is robust enough to fetch your Airport device name even if it isn't en1.

I was going to write my own bluetooth but I saw yours already. I guess I'll have to hold off for a day or two so I forget what your code looked like and then dive into terminal to figure it out for myself.

Great stuff with the growl notifications though!

Not to shamelessly toss a plug in here but I do some work with AppleScripts for useful Mac power user utilties on mysite if you're interested. http://alxndrmlr.biz

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby ptujec » Tue Jan 11, 2011 11:24 pm

alxndrmlr wrote:I just wrote my own script for this today and was notified by @ptujec about this thread so I thought I would share my solution.

Great!

I implemented the Growl part into your version

Code: Select all

-- http://alxndrmlr.biz/posts/toggle-wifi-on-off-with-applescript

# Toggle Airport Device On/Off
#
# This script will either turn on or off
# your AirPort card based on its current state.

# Fetch the name of your AirPort Device
set airPortDevice to do shell script "/usr/sbin/networksetup -listallhardwareports | awk '{if($3==\"AirPort\"){getline;print}}' | awk '{print $2}'"

# Fetch the current state of the AirPort device
set airPortPower to do shell script ("networksetup -getairportpower " & airPortDevice & " | awk '{print $4}'")

if airPortPower is equal to "on" then
   toggleWifi("off", airPortDevice)
   set apStatus to false
else
   toggleWifi("on", airPortDevice)
   set apStatus to true
end if

on toggleWifi(value, device)
   do shell script ("/usr/sbin/networksetup -setairportpower " & device & " " & value)
end toggleWifi

---

tell application "GrowlHelperApp"
   -- Tell Growl we want to send a notification, use the Airport Utility icon
   register as application ¬
      "Airport AppleScript" all notifications {"Airport Notification"} ¬
      default notifications {"Airport Notification"} ¬
      icon of application "Airport Utility"
   if apStatus is true then
      notify with name ¬
         "Airport Notification" title ¬
         "Airport status" description ¬
         "Airport is now ON." application name "Airport AppleScript"
   else
      notify with name ¬
         "Airport Notification" title ¬
         "Airport status" description ¬
         "Airport is now OFF." application name "Airport AppleScript"
   end if
end tell

sjk
Wizard
Wizard
Posts: 315
Joined: Thu Sep 13, 2007 9:46 pm
Location: Eugene
Contact:

Re: Turn Wi-Fi / Bluetooth on/off with LaunchBar

Postby sjk » Wed Jan 12, 2011 2:19 am

alxndrmlr wrote:I just wrote my own script for this today …
That is robust enough to fetch your Airport device name even if it isn't en1.

Thanks for posting that. Looks like:

Code: Select all

networksetup -listallhardwareports | awk '{if($3==\"AirPort\"){getline;print}}' | awk '{print $2}'"

… can be simplified to:

Code: Select all

networksetup -getmacaddress AirPort | awk '{ print $3 }'

And of course both assume an AirPort interface exists for the script to work properly. :)


Return to “LaunchBar Actions”

Who is online

Users browsing this forum: No registered users and 4 guests