Page 2 of 2

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

Posted: Mon Aug 29, 2011 8:04 pm
by teedoff087
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

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

Posted: Thu Oct 13, 2011 3:54 pm
by Saimabaig
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.

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

Posted: Sun Nov 13, 2011 5:12 pm
by waywalker
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! :)

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

Posted: Fri Jul 18, 2014 6:19 pm
by tim_diggins
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

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

Posted: Wed Apr 01, 2015 3:10 am
by ptim
tx for the update @tim_diggins!