Control iTunes from within Max using shell and osascript to send applescript!

    Mar 30 2011 | 4:12 pm
    This took me a while to figure out, with a lot of hard work already done for me (thanks Philippe OLLIVIER!). I realize this is not a new concept. But I thought since I spent days hunting down details, it might save someone the hassle. I added functionality like:
    -Command the iTunes EQ presets (and any new ones you save) -Command your iTunes playlists -Refined FF(cue) and RW(cue) to toggle on/off for precise cue-ing -Auto-play start: as soon as iTunes is launched, it will begin playing, and at a volume of 50 (out of 100). I actually set a delay of several seconds to give iTunes a chance, since it might be synching up with your ipod too... Victoria will greet you also (just change the name from "Martin" to yours, lol.
    The reason I am making this patch, is because I am using Max to control functions in my car, like the TVIS system (variable intake runner butterfly valves) using a microcontroller, Maxuino, and an aircraft servo. And since there is no room to have a laptop open all the time around the dash area, I am displaying TVIS function, Air-to-water intercooler temps, and stereo controls on my iTouch, which is mounted like a multi-gauge near my console. The iTouch controls my laptop (which can be in the trunk in a case, or under my seat, etc) via an ad-hoc wifi connection. I am using TouchOSC. And since I will have my laptop with me in the car often, I may as well get rid of my old deck/10-disc changer, and put the laptop and iTouch to good use. Instead of getting the soundfeed from the iTouch, I am leaving the iTouch as wireless, and controlling my laptop to send the sound. This allows for higher-quality soundfiles to be played (Apple lossless etc instead of 128 MP3 settings), as well as I will be installing a firewire connection to my amps. I hate the degradation of sound using an ipod with a radio frequency to the stereo deck, as well as the clutter of connecting cables around the dash.
    I am currently completing the stereo portion of the iTouch control page. I have set up the stereo patch with mostly toggles, so that you only need one button each for play/pause, EQ enabled/disabled, mute, shuffle on/off, and so forth. I have set up each EQ preset individually, because I won't be able to display a variable dialogue or number box on the iTouch. Just change the names of the presets to match your own. Same deal with the playlists, just change them to match your own iTunes playlists. Before I start making all the connections to the OSC objects, I though i'd share the iTunes portion of the patch.
    I actually made several youtube videos explaining what I am doing, although none of them so far deal with the stereo/iTunes portion of it:
    I am impressed with the ability of the iTouch to display and control functions. The iTouch pages are reasonably programmable, including labels etc, thanks to TouchOSC... which has an acclerometer function ready to go too.
    Anyways, I am rambling, so here is just the Maxpatch to control iTunes. Hope someone enjoys it! :)

    • Mar 30 2011 | 9:37 pm
      Looks great! Don't be afraid to hide all those message box commands in a [coll] and access them with something like [umenu]!
    • Mar 31 2011 | 5:06 am
      Thanks! Yes that occurred to me, however, since the TouchOSC and iTouch won't display things like umenu's (it has single toggles and multi-toggle panels, dials, sliders, led's, buttons, labels, etc, and I have to figure out how to feed the info back correctly to the iTouch to have sliders etc be in synch on both machines) I figured I would leave them out to be edited, and since peeps would have to edit some of the EQ presets and virtually all of the playlists, etc, I thought I would throw it up as is.
      When I do have the other stuff figured out, I will return here and finish off the patch for visual in a nice presentation "player" look... and update the patch. For now, its functionality to control iTunes from Max is complete.
      I especially like the two playlists "iTunes DJ" and "Top 25 Most Played Songs"... acts as variable and shuffle playlists... For me, controlling iTunes with Max is paramount to the setup in my car. I have always wanted to have MaxMSP available in my car! Its like... a whole new world... lol ;)
    • Mar 31 2011 | 9:15 am
      What you really need to do is get a copy of some voice recognition software and have max grab the text you speak and then perform an itunes search on the string and start playing the tracks it returns. Definitely not impossible with max!
    • Apr 03 2011 | 12:41 am
      Wow, you guys are blowing my mind all over again. You're actually using Max to control your car's engine while you drive?! Do you have a test track in your backyard or something? Next time I'm on the highway I'm going to wonder if that guy swerving maybe forgot to send "set" to a message box, or confused his atoi/itoa's or something.
      & Can you help me write a patch to fix the transmission in my Ford cargo van?
    • Apr 06 2011 | 9:13 am
      LOL No, but I could write a patch that would tell your auto tranny to downshift or upshift, using a strong actuator motor.
      Cars are already doing it these days, with the software/hardware to park themselves, correct? Essentially servos (or steering assist in this case) with a preset chain of commands it just runs through... plus add proximity sensors for fine adjustment or failsafes.
      I am currently going to use it only on a non-essential system like the TVIS, where if the system fails and the TVIS is locked open or closed, performance and power are affected, but no harm is done. OEM manufacturers devote a lot of time to testing ECU's for issues like this. My iTouch also makes a great display for various temp sensors and controls (like the TVIS), and, I am nearing the completion of the Stereo page on the iTouch. It currently has 24 EQ presets and 32 playlists all of which are visibly labelled, and the basic ff/rew plus cue, volume, play/pause, and power on (iTunes launch), all on one tiny iTouch touchscreen. Wireless, and plays lossless soundfiles which will go to my amps via firewire from the computer... hard to beat that for sound quality. No MP3's via a radio adapter here! I will shoot a quick video soon.
      But yup, lots of testing. Nothing new to anyone tuning their own car with a standalone ecu or tuning software, anyways... the arduino just provides *lots* more options.
      Haha Luke, its funny you should say that... I was just playing with the voice recognition on my Macbook Pro tonight... leaves quite a bit to be desired...
    • Apr 06 2011 | 9:39 am
      I have also updated the patch on the stereo page to have a memory of what playlist, EQ setting, and volume it was at. Big deal, right?? iTunes already does this anyway right?? Well, its getting Max to remember these settings when it is launched, and getting the iTouch to accurately display the properly recalled settings, since they are different every time Max and iTunes close down (because we change them!)... so they have to be auto-saved, auto-recalled on launch, and auto-displayed on the iTouch.
      lol, sounds so easy.
      The patch is big, needless to say... thousands and thousands of connections, especially since the 32-button multi-toggle for the playlists has only one button on at a time, just like a large "radiogroup", except I can't use the radiogroup object on the iTouch display, only basic dials/toggles etc... so it had to be built from scratch in Max, each "on" toggle in turn turning off the remaining 31 toggles... so thats 32x32 (over a thousand) connections right there. But, its worth it :).
    • Apr 06 2011 | 10:46 am
      Haha I bet there's a better way to organise those thousand connections!
      The built in voice recognition isn't perfect, but you can teach it a few commands using applescript which will simulate key presses which you can grab using max. The other option is to splash out on something like MacSpeech Dictate which you need to train to recognise your voice but then works much much better.
    • Apr 06 2011 | 5:54 pm
      I could have used a slider or a dial to switch the playlists, but then the layout on the iTouch is not compact... it would take up the whole screen just to display the playlists, because you need the labels (the names of the playlists) displayed around the dial... which also doesn't look like a professional automotive display to me.... lol. Its a tradeoff between neatness/compactness/multi-usage and complexity to connect.
      Using radiogroup it is possible to first send out a "zero-bang" to turn off all playlist buttons, then (just afterwards) output the chosen number (selected button) to turn only it on. That does eliminate a lot of connections. But I did not pursue this method all the way to see if it can make TouchOSC both display and relay the choices properly.
      Its a curent limitation of TouchOSC. What would solve *everything* is if the TouchOSC had a message box, (at the very least) so that it could display one playlist at a time, and we could select the playlists with two buttons for up/down. Simple. But it doesnt exist yet.
      Thanks for the suggestions! I will look into MacSpeech Dictate. It would be nice to be able to control some things hands free. End result my car will be faster, with better displays, and my eyes can remain on the road where they should be!
    • Apr 06 2011 | 9:16 pm
      You might also want to look into the fantastick app for iDevices. It's not quite the same as TouchOSC in that you have to provide the drawing commands to the screen but it would allow for a lot more control and customisation.
    • Apr 08 2011 | 6:35 am
      I have not checked that out at all... will do.
      I solved an annoying little addressing issue tonight... I was getting error messages in my Max window telling me that I scoured my patch for the source of this phantom "bang"...
      I finally came across this statement from Matt Wright: "In my mind the key thing about OSC-route is that it dispatches one node of the address space with absolutely no distinction between a branch node (subcontainer) or leaf node (method). E.g., if you have [OSC-route /foo] and you send in "/foo/bar 1 2 3" then it outputs "/bar 1 2 3". If you send in "/foo /bar 1 2 3" (address "/foo", arguments the string "/bar" followed by three integers) then you get *the exact same output* of "/bar 1 2 3". If you send in "/foo 1 2 3" then it outputs "1 2 3". If you send in just "/foo" then it outputs a bang."
      His last sentence was the kicker. When I would switch pages on my iTouch, just the "Stereo" page was causing the error message... I realized the name of the page and the sub-heading were matched, and one was unnecessary... in the terms above, I had the [OSC-route /Stereo] and when I would switch the iTouch to the "Stereo" page, it would send it "/Stereo"... and hence the bang. I placed the designation "Stereo" in front of every button-name instead. So when the iTouch swiched to the "Stereo" page, all was perfect.
      Silly-annoying really, lol.
    • Apr 13 2011 | 3:35 pm
      I have completed the iTouch multi-interface/display. The TVIS section has multi-gauges to indicate exactly what the TVIS does in relation to RPM. I also added memory to the A2W IC display, so that both ambient and manifold temps will display current temps and the recent highest reached temps. The third display page has a wideband Air-fuel ratio gauge, and the fourth page is my stereo system complete with playlists, EQ presets, and multi-layered to include all the usual controls. It actually controls iTunes better and faster than iTunes can be controlled on the computer, lol. I also threw in voice confirmation for making TVIS selections. Check out the fourth video:
    • Jan 20 2012 | 9:07 pm
      How can i get my hands on this [shell] object ?
      I would really LOVE to get my hands on this patch. I'm making a voice/ iphone controlled coffeetable 2.0 living room centre robot ( ask if you want to know more ). and it would be great if i can also control itunes with it.
      please respond,
      thanks in advance, sorry for the bad english ( and i'm not an expert with max, but i really love it )
      ps. i'm running win7 i hope this is not mac only !
      greetings !
    • Mar 12 2012 | 1:57 pm
      That sounds like a cool project! The [shell] object can be found here:
      More information where I sourced mine from can be found in this thread:
      and Doug's AppleScripts for iTunes:
      And, my patch is included at the bottom of my first post :). It's just the original iTunes portion... it has ballooned considerably now, so just ask if there are particular tasks that you want to achieve and I can help you out.
      Hope that helps, and good luck!
    • Mar 12 2012 | 7:32 pm
      I have started a new post to detail progress with the rest of the "Max MSP in my car!" project, going beyond the scope of the title of this thread which is focussed on iTunes control.