I've been playing around with automation recently (more on that in a later post), and I thought that being able to control a network attached Onkyo receiver from my Mac sounded like a cool thing to do. Onkyo provide a free iOS app to use as a remote control, so I wondered if there was an API available that would let me do the same thing from a Mac. Then I found that someone had already implemented such as thing: OnkyMote is a great little Mac app (US$2.99) by Tomas Larsson that sits in your menu bar and allows you to power on/off your receiver, select an input source, or adjust the volume.
With the problem half solved, the next step was to use Applescript to control OnkyMote. As a proof of concept, I decided to write and schedule a script that would turn on the radio every day at 7.30am.
The first step was to open the Applescript Editor (In /Applications/Utilities), and enter the following AppleScript:
-- Switch on Tuner with volume 20: onkyoOn("TUNER", 2) of me on onkyoOn(input, aVolume) try tell application "Finder" activate open application file "OnkyMote.app" of folder "Applications" of startup disk delay 0.5 end tell tell application "System Events" tell process "OnkyMote" -- Click on top level menu, to load the menu, and then select the source click menu bar item 1 of menu bar 1 click menu item input of menu 1 of menu bar item 1 of menu bar 1 -- Click on top level menu, to load the menu, find and adjust the volume slider click menu bar item 1 of menu bar 1 set names to name of menu items of menu 1 of menu bar item 1 of menu bar 1 repeat with i from (count of names) to 1 by -1 if item i of names starts with "Volume:" then set value of slider of menu item (i + 1) of menu 1 of menu bar item 1 of menu bar 1 to aVolume exit repeat end if end repeat -- Click on the Label to dismiss the menu click menu item "Devices:" of menu 1 of menu bar item 1 of menu bar 1 end tell end tell end try end onkyoOn
Once the script had compiled successfully (By clicking the Compile button, which also formats the code nicely), I saved the file, ensuring that I selected the file format as "Application".
I then configured the application to be an alert for a new repeating iCal event, selecting an alert type of "Open File", and selecting the application file.
And that's pretty much it - with this initial script working, it now allows my Mac mini to switch on the receiver, select itself as the source, and play any audio I want when a particular event occurs, and that opens up all sorts of automation possibilities for the future....