Philips Hue Control From AppleScript (For Use in iCal and Calendar)

UPDATE:I created this entry before an API came along that made all this easier. Some great documentation on how to do all of the below is listed here

The Hue Series LED bulbs from Philips are very hackable and can be controlled via simple HTML Put commands. I have assembled a few things to get you started in some simple preset control via AppleScripts. I’m using this method to create an appointment in Calendar to automatically turn on and off these lights.

Before you start with all this, you should know/set the IP address of your base station. You can set the IP address of your bridge using the Hue app on iOS.  Go to the settings in the Hue app and then click on My Bridge/Network Settings. Turn off the DHCP switch and then set your IP below.  Click Save.

So now that you know your IP address, you’ll need to configure your bridge to accept commands. Go to this site ( and follow the first page of steps up past where you create the user “newdeveloper”.

You’ll need to know which Hue Lamp you wish to control. The order that the lamps appear in the myhue website or the iphone app, is the same order that they are numbered. I’ve put markers into the scripts where you’ll paste and enter this info.

The first script you can use to see what your lamp is doing. This is useful to get the values of the color you have selected through the app that you can then paste those values into the other scripts to recreate the values that you set.  So first, using the app, set your lamp to the desired color and intensity.  After editing the script to include your IP address, API Key, and correct lamp; Run this first script to see the lamp values:

Get Bulb Status

set pollBulb to do shell script "curl"

The important bits you’ll need from this are the Brightness (bri), Hue (hue), and Saturation (sat). Here are some sample values

{\"on\": true,\"bri\": 254,\"hue\": 12813,\"sat\": 219,\"xy\":[0.5196,0.4141],\"ct\":484}

To turn the lamp on at the value you found, you’ll change this next script to reflect what you found:

Lamp On

set turnOn to the quoted form of "{\"on\": true,\"bri\": 254,\"hue\": 15331,\"sat\": 121}"
do shell script "curl --request PUT --data " & turnOn & ""

Finally, here is a script to turn the lamp off:

Lamp Off

set turnOn to the quoted form of "{\"on\": false,\"bri\": 254,\"hue\":15331,\"sat\":121}"
do shell script "curl --request PUT --data " & turnOn & ""

So there ya go. Applescript yourself away.

Source for the above info from


Mountain Lion Archive Bug

There is a bug in Mountain Lion (10.8.2) where you go to click on a compressed file to unzip it and your system just hangs and wont unzip it, forcing you to force quit the unarchiver.  Until they fix the bug, you can run this workflow to quickly kill the correct service. It will restart when you try to unarchive something again.  Drop this into your ~/Library/Services folder and then you should see it in the Services Menu under every application drop down on the menu bar. If you don’t see the service appear, open Services Preferences and scroll down to make sure there is a check mark next to the same of this workflow.

Compressor Fix Workflow

Q: But wait, how do I unzip this if the reason I came here was to get my unarchiver working again?
A: You can either reboot or type the following into Terminal:

sudo killall -KILL appleeventsd

The actual workflow is an applescript that does the following:

do shell script "sudo killall -KILL appleeventsd" with administrator privileges

Here’s the source:


Outlook for Mac Notification Center New Message Alert

Using MacPorts, there is a program called “Terminal Notifier” that can send alerts to Notification Center in Mountain Lion based off of a command line entry and thus an Applescript. Obviously, you can have a lot of fun with that – but I specifically found it so that I could send a new message alert from Outlook because Microsoft only has such a notification appear on the active desktop and I use several of them in Mission Control. I compiled this information from these sites:

To get this to work isn’t so bad once you have MacPorts installed, which I’ve referenced earlier.

  • Assuming MacPorts is already installed, run the selfupdate command (also listed in that earlier post).
  • Install Terminal Notifier:
    sudo port install terminal-notifier
  • Download and put this AppleScript into your Documents/Microsoft User Data/Outlook Script Menu Items (you don’t have to put it there, but just for organizational sake, might as well). Sure it says Growl in everything below as that is what I originally used it for but then changed it to accommodate Notification Center instead:Improved Growl New Mail.scpt
  • In Outlook, create a new rule that will run the script based on your criteria. Here’s mine:

That’s all there is to it.


MacPorts Installation and Sending UDP Messages from the Command Line and Applescript

UPDATE: A very easy tool to send UDP commands can be found here

Spurred on by one of my colleagues, I found a way to be able to send UDP messages from the command line without a lot of fuss. Granted, you do have to install some things on the backend, and any applescript you make wont be able to run on any computer unless this same process has been completed, but it’s still useful if you need to send UDP messages (say to a Pharos/Mosaic/Eos). This was all done in Mountain Lion 10.8.2:

  • Follow the instructions here up to the point where it gets you to install the game – don’t do that. They refer to Darwin Ports everywhere – it’s actually called MacPorts now.
  • You can find the install for MacPorts here:
  • When in the instructions on the site, it tells you to change to the darwin ports directory, this is the command instead:
    cd /opt/local/var/macports
  • Anytime you see “dports” substitute “macports”.
  • After you’ve gotten through all the above, you’ll want to install the program “socat” which will allow you to send the UDP messages:
    sudo port install socat
  • Once that has installed sucessfully, you should now be able to send UDP messages now like the following. You would replace “HELLO” with the text you wish to send and then change the IP and port number to the device you’re sending to:
    echo "HELLO" | socat – UDP-DATAGRAM:,broadcast

Now for the actual Applescript, that part is easy, you just have to insert a “do shell script” command into an applescript where you can ask for variables, etc.  Here’s an example:

set UDPstring to the quoted form of "Hello_Does_This_Work"

do shell script "echo " & UDPstring & " | opt/local/bin/socat - UDP-DATAGRAM:,broadcast"

MacPorts has some other fun things you can install, like Terminal Notifier for instance. Here are some commands to remember:

  • To make sure that your installation is up to date and to upgrade anything you may have installed through MacPorts, run these two commands:
    sudo port -v selfupdate
    port upgrade outdated
  • To search for a particular program or to list all the programs (replace {name} with your search criteria:
    port search {name}
    port list
  • Finally again, to install a new port, the command is:
    sudo port install {portname}

As usual, YMMV and always backup your computer before you do something you’re unsure of.  Good Luck!