iTunes, Pandora, AirFoil Integration  (Script)

Contributed by: Doug Kress

Overview

This package is used to simplify access to and inneroperability of three applications:

  • iTunes

  • PandoraBoy (http://code.google.com/p/pandoraboy/) - Plays Pandra "radio stations"

  • AirFoil (http://www.rogueamoeba.com/airfoil/mac/) - used to send audio from any application to the AirPort Express units, apple TV(not just iTunes)

My goal is to have a way to control my whole-house audio system that plays iTunes, Pandora and making announcements.

if iTunes were the only application involved, access is very simple - and the fitures in the scripts included in Indigo would more than suffice. When one adds the complexity of adding Pandora to the mix, it gets a little more complex:

  • AirPort Express devices only work with iTunes by default

  • Pandora - a web service - is not easily controlled with Applescript.

  • Most likely, you would not want iTunes and Pandora playing simultaneously. A random mashup of Cake and AC/DC is less pleasing to the ear than one might expect.

A quick note on Pandora: After some brief testing with Pandora, I quickly learned that paying for the "Pandora One" is a great value. The environment described here is not intended for use with the ad-based, free Pandora experience - the frequent pauses and ads make the environment unworkable.

To solve the above issues, two applications were required:

  • AirFoil - an inexpensive (but not free) application that allows sending audio from any application to Airport Express devices, Macs, Apple TVs, iPhones and iPod Touches.

  • PandoraBoy - a simple wrapper application that allows AppleScript control of the Pandora web-based service.

Installation

There are two scripts included in this package that allows simplified control of these applications:

  • audioAppStatusUpdater.scpt

Installation directory: /Library/Application Support/Perceptive Automation/Indigo 4/Scripts/Background/

To install this script:

  • Press File / New Trigger Action

  • set Type to "Indigo Server Startup"

  • click the Action tab

  • set Type to "Execute Applescript"

  • Select the "File" radio button

  • Select the script in the dialog box.

This script monotors all three applications, and updates various Indigo Server variables. This script can work as a stand-alone script if you simply would like to have access with the variables, or in conjunction with audioAppControll.scpt to allow full control.

This script will not interfere with the operation of the included "iTunes sync.scpt" - they update a different set of variables and will not conflict with one another.

  • audioAppControl.scpt

Installation directory: /Library/Application Support/Perceptive Automation/Indigo 4/Scripts/Attachments/

This is the control script intended to go into the "Attachments" folder. It does require that "audioStatusUpdater.scpt" be installed and running before using the functions provided within. (some functionality may work, but most of the iTunes and PandoraBoy controls will do nothing).

The functions within do not conflict with those in "iTunes attachment.scpt" - however, iTunes controll - primary the start function - will NOT stop PandoraBoy, if it is currently playing, causing both to play simultaneously (avoid those random mashups!)

Usage

This script has a lot of utility functions for dealing with AirFoil, iTunes and PandoraBoy. Some of the included functions are:

  • announceMessage(strMessage)

Lowers volume of either individual application and use "say" command to speak the message. If using AirFoil, you need to set AirFoil to "System Audio" (see connectToSource() below). Because I use the AppleScript "Say" command, this uses the system's Text-to-Speach preferences found in the preferences pane.

  • announceCurrentTrack()

Uses above function to announce the current track, artist and album.

  • announcePlaylist()

Announces the current playlist / station.

  • toggleMusic()

If nothing is playing, iTunes will start. Otherwise, whatever is currently playing will be stopped, and the other player will start. This is the function I use for starting music from a button.

  • startPandoraBoy()

Stops iTunes, if playing, and starts PandoraBoy.

  • startITunes()

Stops PandoraBoy, if playing, and starts iTunes

  • stopMusic()

Stops either app, if one is playing.

  • nextTrack()

Skip to the next track of the currently playing source.

  • nextPlaylist()

Skip to the next playlist (currently works for PandoraBoy, but not yet for iTunes)