Step 6: Software - Computer Code
There are several options to give the Arduino the ability to interact with computer applications. I've chosen the most basic, although more advanced methods are covered on other Instructables. In my method, the Arduino communicates with a C-based program running on the terminal, which in turn runs an Applescript that will perform the desired action in the application. It's a roundabout method, but it utilizes preexisting software architectures in the operating system and thus requires the least coding effort on my part.
The first step to making this work is to download the C code to give the Arduino access to the computer's terminal program. It was written by Tod Kurt, and is available off this website. However, after much experimentation, I realized that my coding skills weren't up to par with modifying the code to fit my needs (I needed the serial communications to cause the applescript to run). Luckily, another instructable user has done work in this area. User aymans wrote code in his foot switch instructable that modifies Tod Kurt's code to allow serial communications from the arduino to execute applescripts. This turned out to be exactly what I needed, so I modified my current arduino code and files to fit his code. To download his code, visit his instructable
You will also need to download or write your own Applescript to switch the track in iTunes. I've included one attached to this step, but you can always write your own and use it for whatever application and action you'd like. If you write your own, make sure to name it "1.app" and save it in the same folder as the rest of your files to make it work with the other code.
Now that you have all the files, we can try it out. Make sure iTunes is on and that your set-up arduino code is uploaded to your device. Then execute the arduino-serial program (after its been compiled of course) with the command "./arduino-serial -b 9600 -p [your arduino serial port] -R". Replace the brackets with your arduino's serial port, which can be found in the Arduino IDE under the Tools menu. Once this is done, everything should work. Test it out, feel the power of controlling your computer without even touching it. Sure it's a lot of work for a glorified button, but over engineering is always fun.