This week we'll create a simple REALbasic application that enables you to churn out custom iTunes visual plugins. Have a fun message you want to surprise a co-worker or loved one with? Try passing it along via iTunes to really get their attention.
I know what you're saying.... "You can't build an iTunes plugin with REALbasic!". Fundamentally this is true. Using a few tricks, though, we can fake it. Using an existing plugin, we will replace a few items within it and build a new copy of the plugin with the revised settings, thus making a "new" plugin. The end effect is an iTunes plugin of your very own that happily draws your name in multiple colors when run.
Build the Interface
This week's interface is drop-dead simple to create. Launch REALbasic, open Window1 and drag an EditField, StaticText, and PushButton into the window. The EditField will be used as a place to enter your name. Pressing the PushButton will:
To give you an idea of how this might look:
Add the Code
Before we jump in and start coding, you need to know a few things. First, the plugins you will create are based on a template plugin named "ResexPlugin". When installed, this plugin is a fully functioning. It displays the word "ResExcellence" in flickering colors. Further, the name of the plugin (as it appears in the iTunes menu) is "ResEx Plugin". If you do a quick count, you will see the following:
| ResExcellence | 13 characters long |
| ResEx Plugin | 12 characters long |
The plan is to replace these two bits of information with your own data. Since this resides within the data fork of the plugin, it is vital that you not change the length of either string. Changing them will likely render the plugin useless. Don't need all the characters? We'll fill in any blank spots with a "space", since it maintains the string lengths yet won't alter the display.
The code is fairly minimal this week as well. For starters, double-click PushButton1 and enter the following code:
dim src,dest as folderItemIf you were paying attention, you may have noticed the undefined CopyFileOrFolder call. This leads us to our last code example. Select Edit->New Method and create a new method:
You may recognize this method from the Language Reference in REALbasic. In fact, if you navigate to the "FolderItem" entry in the Language Reference, you will find the code for CopyFileOrFolder, which you can drag from into your new method. In case you like to type, the code is:
Dim i as IntegerConclusion
That's it! Test the project and when you're happy with the results, build the final application. The resulting plugin should produce somthing that looks like this:
Don't forget to keep a copy of the template plugin (entitled "ResexPlugin") in the same folder as your application. As usual, you can download the application and completed project. It also includes the C source code in case you are interested in building your own iTunes plugin in CodeWarrior. Until next week!