Please note this post has not been updated and may contain broken links or outdated information.A few years ago I started using LaunchBar, a great keyboard-driven productivity tool. As someone who spends their entire work day in front of a computer, I can't imagine going back to doing things without it. Launching applications, adding events to my calendar, running Google and Wikipedia searches, accessing my clipboard history, using the built-in calculator... it can tackle a lot. In fact, I know there are tons of features I'm still not using. Soon after I adopted it I realized I wanted to use it to quickly enable or disable some of the network settings in my system preferences. I work out of the office semi-regularly, and the main shortcut I wanted was to connect to my company's VPN so I can work securely. Using LaunchBar, I'd gotten used to the speed with which I could get common tasks done, and dragging my cursor up to the Finder's menubar to turn the VPN off and on seemed, well, laborious. But, high on the initial boost in productivity LaunchBar gave me, I put off figuring out how to do it. For years (so much for productivity). Yesterday, I finally took some time to set it up and I am now happily — and quickly — toggling off and on several of my network services.
Step 1: Write Some AppleScriptsOr, in my case, just do a Google search and use other people's scripts. Open AppleScript Editor on your mac (/Applications/Utilities/AppleScript Editor), and create a new file for each of these that you'd like to use. In theory you can save the files anywhere you like, but saving them somewhere in your home directory is the surest way to have LaunchBar find them and add them to its index.
Toggle VPN( source)
tell application \"System Events\" tell current location of network preferences set VPNservice to service \"Your VPN Name\" -- name of the VPN service set isConnected to connected of current configuration of VPNservice if isConnected then disconnect VPNservice else connect VPNservice end if end tell end tell
Toggle WiFi( source)
set res to do shell script airportUtil & \" -p || exit 0\" property airportUtil : \"/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I\" 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
Toggle Bluetooth( source)
tell application \"System Preferences\" reveal pane id \"com.apple.preferences.Bluetooth\" -- activate -- optional, just if you want to display the window tell application \"System Events\" to tell process \"System Preferences\" click checkbox \"On\" of window 1 end tell quit end tell