Turn Wi-Fi / Bluetooth on/off with LaunchBar

Sharing and discussing custom actions for LaunchBar
teedoff087
Posts: 14
Joined: Wed Sep 08, 2010 8:43 pm

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

Postby teedoff087 » Mon Aug 29, 2011 8:04 pm

Modified the Wi-Fi script a little bit for Lion Compatibility. AirPort is called Wi-Fi now in Lion.

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==\"Wi-Fi\"){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 ¬
      "Wi-Fi AppleScript" all notifications {"Wi-Fi Notification"} ¬
      default notifications {"Wi-Fi Notification"} ¬
      icon of application "AirPort Utility"
   if apStatus is true then
      notify with name ¬
         "Wi-Fi Notification" title ¬
         "Wi-Fi" description ¬
         "Wi-Fi is now ON." application name "Wi-Fi AppleScript"
   else
      notify with name ¬
         "Wi-Fi Notification" title ¬
         "Wi-Fi" description ¬
         "Wi-Fi is now OFF." application name "Wi-Fi AppleScript"
   end if
end tell

Saimabaig
Posts: 1
Joined: Thu Oct 13, 2011 3:52 pm
Contact:

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

Postby Saimabaig » Thu Oct 13, 2011 3:54 pm

jordi wrote: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

Great.

waywalker
Posts: 16
Joined: Tue Oct 27, 2009 6:55 pm

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

Postby waywalker » Sun Nov 13, 2011 5:12 pm

teedoff087 wrote:Modified the Wi-Fi script a little bit for Lion Compatibility. AirPort is called Wi-Fi now in Lion.


Works like a charm! Saved me a ton of time, thanks! :)

tim_diggins
Posts: 1
Joined: Fri Jul 18, 2014 6:16 pm

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

Postby tim_diggins » Fri Jul 18, 2014 6:19 pm

I've just updated the blue tooth applescript for more recent versions of blueutil (1.0.0) and Growl (2.1.3)

Code: Select all

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

if bt_status is "1" then
   do shell script "/usr/local/bin/blueutil power 0"
else
   do shell script "/usr/local/bin/blueutil power 1"
end if

tell application "Growl"
   -- 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 "1" then
      notify with name ¬
         "Bluetooth Notification" title ¬
         "Bluetooth status" description ¬
         "Bluetooth is now OFF." application name "Bluetooth AppleScript"
   else
      notify with name ¬
         "Bluetooth Notification" title ¬
         "Bluetooth status" description ¬
         "Bluetooth is now ON" application name "Bluetooth AppleScript"
   end if
end tell

ptim
Rank 2
Rank 2
Posts: 43
Joined: Fri Nov 18, 2011 6:33 pm

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

Postby ptim » Wed Apr 01, 2015 3:10 am

tx for the update @tim_diggins!


Return to “LaunchBar Actions”

Who is online

Users browsing this forum: No registered users and 1 guest