DesktopX as an application customization tool
from
JoeUser Forums
Recently I published a "work in progress" version of an iTunes object (Link)
which shows how DesktopX can be used to interact with applications installed on
your computer.
This article is designed to introduce people into how this was achieved so that they can try to use DesktopX to do similar things. It is not designed to be an exhaustive guide to scripting, nor an exhaustive guide to interacting with iTunes. Rather, it is a simple introduction which specifies how to achieve some of the basics so people can develop objects themselves.
OK, so let's get started. What is ideal is a guide to the application's object model. Just like DesktopX, other applications have various properties and methods that can be accessed. Apple proves a SDK for iTunes that includes such a help file. You can download this help file here: Link
Alternatively, you can use a tool to view these methods. There are several available, but I find the simplest and most effective tool Visual Basic CCE. I will use this in this article, but you can you your preferred tool. You can download VB CCE free from here: Link
So, let's get started ...
To start with create an object, and create a new script for it. What we want to do here is create an object that can represent iTunes so that other objects can interact with it. For this reason I will name the object "iTunes". The key command here is CreateObject. You need to know what to "create" and the iTunes literature tells me that I need to create an iTunes.Application object. I'm creating a variable to represent this.

We can now refer to iTunes directly. Within this object we can use iTunesApp to refer to the object, and externally we can refer to it using DesktopX.ScriptObject("iTunes").iTunesApp. Note that we need to define the iTunesApp variable outside the code so it can be accessed by other objects.
If you don't have documentation but you know an application can be scripted, Google can often be the savour. Do a search for "createobject iTunes" or "createobject Outlook" and you probably find a site that tells you what you need to know. Just remember that in DesktopX you don't need the "WScript." prefix.
OK, so we can now really start to play with iTunes. Let's have a look at the Object Model using VB CCE.
Launch VB and click OK on the dialog. it doesn't really matter what you select as we're not actually creating anything. The first thing to do is tell VB that you want to be using iTunes. From the "Project" menu, select "References". You can now see all the things on your computer that you can refer to using this technique. Check the reference to the iTunes 1.1 Type Library and click "OK".

If you now go to the "View" menu and choose "Object Browser" - this is the tool you really need as your reference. From the Libraries combo, select the iTunesLib reference that you just added. All of a sudden you will be presented with information about everything you can do with iTunes.

Globals refers to the base iTunesApp object that you created and on the right are all the properties and methods associated with that. The methods have the green icon like BackTrack and Play. So, for example you can do iTunesApp.Play() to play the currently selected track. If you look at the properties these are the elements of iTunes you will need to interact with, and it helps to have some knowledge of the application itself. You will probably know that the starting point with iTunes is selecting the source for your music, which can be the "Library", an "Audio CD" or "iPod" amongst other items. With this in mind check out the Sources property.

What this tells you is that if you refer to iTunesApp.Sources then you are referring to a collection of objects known as IITSourceCollection. If you look on the left you will see the IITSourceCollection class. Looking at that you will see that it has 3 properties and we will use the "Count" and "Item". You will see that each "Item" is an IITSource. The iTunes help file is actually more revealing that VB at this point. You can see that each source has a kind.
We can now start to use DXScript to do something useful. Create a new object called iTunesSources and make it a DXCombo ActiveX control. This will be a place to display all the possible sources.
OK, so back to our iTunes object. Let's write that script, and a fairly simple one at that now we know what we're dealing with. We need to add the sources to the combo box, and as part of that process we need to convert the "Kind" into something useful rather than just a number. The documentation tells me all the ITSourceKind variants.

What we have now is a combo box with all our sources on there.

OK so we have all our sources. What we now want to do is to be able to see what is available on these sources. I'm going to focus on the main Library as there are variances with things like the Radio Player. Therefore, assume you should only select the Library in this demo or you may get some oddites.
In iTunes, the Library will have Playlists associated with it and each playlist will have tracks associated with it. Create 2 DXListbox objects; "iTunesPlaylists" and "iTunesTracks".
OK, so now, we need to add script to the list of sources so when we click it it displays the Playlists. Again this is a similar script. You can see from the documentation that the IITPlayListCollection works basically the same way as the collection of sources, so the script is very similar. In fact, it's a little easier because be don't need to translate the kind. If you display a "List of all members" in the documentation you will see that each playlist has a "Name" property.

You now have a list of the playlists available when you click the source. Here's the script for the source combo.

We now just need to do something very similar to display the tracks when you click a playlist. Here's the script for the playlist list.

You now have a series of objects that selects the appropriate tracks based on the source and playlists.

The final thing to do is to play a track when it is clicked. This again is easy to achieve. Just add this code to the tracks list.

That is about it for the basics. Just explore the object model further and the sample object and you can see how far you can develop applications using DesktopX!
Click this link to download the sample objects: Link
This article is designed to introduce people into how this was achieved so that they can try to use DesktopX to do similar things. It is not designed to be an exhaustive guide to scripting, nor an exhaustive guide to interacting with iTunes. Rather, it is a simple introduction which specifies how to achieve some of the basics so people can develop objects themselves.
OK, so let's get started. What is ideal is a guide to the application's object model. Just like DesktopX, other applications have various properties and methods that can be accessed. Apple proves a SDK for iTunes that includes such a help file. You can download this help file here: Link
Alternatively, you can use a tool to view these methods. There are several available, but I find the simplest and most effective tool Visual Basic CCE. I will use this in this article, but you can you your preferred tool. You can download VB CCE free from here: Link
So, let's get started ...
To start with create an object, and create a new script for it. What we want to do here is create an object that can represent iTunes so that other objects can interact with it. For this reason I will name the object "iTunes". The key command here is CreateObject. You need to know what to "create" and the iTunes literature tells me that I need to create an iTunes.Application object. I'm creating a variable to represent this.

We can now refer to iTunes directly. Within this object we can use iTunesApp to refer to the object, and externally we can refer to it using DesktopX.ScriptObject("iTunes").iTunesApp. Note that we need to define the iTunesApp variable outside the code so it can be accessed by other objects.
If you don't have documentation but you know an application can be scripted, Google can often be the savour. Do a search for "createobject iTunes" or "createobject Outlook" and you probably find a site that tells you what you need to know. Just remember that in DesktopX you don't need the "WScript." prefix.
OK, so we can now really start to play with iTunes. Let's have a look at the Object Model using VB CCE.
Launch VB and click OK on the dialog. it doesn't really matter what you select as we're not actually creating anything. The first thing to do is tell VB that you want to be using iTunes. From the "Project" menu, select "References". You can now see all the things on your computer that you can refer to using this technique. Check the reference to the iTunes 1.1 Type Library and click "OK".

If you now go to the "View" menu and choose "Object Browser" - this is the tool you really need as your reference. From the Libraries combo, select the iTunesLib reference that you just added. All of a sudden you will be presented with information about everything you can do with iTunes.

Globals refers to the base iTunesApp object that you created and on the right are all the properties and methods associated with that. The methods have the green icon like BackTrack and Play. So, for example you can do iTunesApp.Play() to play the currently selected track. If you look at the properties these are the elements of iTunes you will need to interact with, and it helps to have some knowledge of the application itself. You will probably know that the starting point with iTunes is selecting the source for your music, which can be the "Library", an "Audio CD" or "iPod" amongst other items. With this in mind check out the Sources property.

What this tells you is that if you refer to iTunesApp.Sources then you are referring to a collection of objects known as IITSourceCollection. If you look on the left you will see the IITSourceCollection class. Looking at that you will see that it has 3 properties and we will use the "Count" and "Item". You will see that each "Item" is an IITSource. The iTunes help file is actually more revealing that VB at this point. You can see that each source has a kind.
We can now start to use DXScript to do something useful. Create a new object called iTunesSources and make it a DXCombo ActiveX control. This will be a place to display all the possible sources.
OK, so back to our iTunes object. Let's write that script, and a fairly simple one at that now we know what we're dealing with. We need to add the sources to the combo box, and as part of that process we need to convert the "Kind" into something useful rather than just a number. The documentation tells me all the ITSourceKind variants.

What we have now is a combo box with all our sources on there.

OK so we have all our sources. What we now want to do is to be able to see what is available on these sources. I'm going to focus on the main Library as there are variances with things like the Radio Player. Therefore, assume you should only select the Library in this demo or you may get some oddites.
In iTunes, the Library will have Playlists associated with it and each playlist will have tracks associated with it. Create 2 DXListbox objects; "iTunesPlaylists" and "iTunesTracks".
OK, so now, we need to add script to the list of sources so when we click it it displays the Playlists. Again this is a similar script. You can see from the documentation that the IITPlayListCollection works basically the same way as the collection of sources, so the script is very similar. In fact, it's a little easier because be don't need to translate the kind. If you display a "List of all members" in the documentation you will see that each playlist has a "Name" property.

You now have a list of the playlists available when you click the source. Here's the script for the source combo.

We now just need to do something very similar to display the tracks when you click a playlist. Here's the script for the playlist list.

You now have a series of objects that selects the appropriate tracks based on the source and playlists.

The final thing to do is to play a track when it is clicked. This again is easy to achieve. Just add this code to the tracks list.

That is about it for the basics. Just explore the object model further and the sample object and you can see how far you can develop applications using DesktopX!
Click this link to download the sample objects: Link