Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I change the Title property of a .WMA file?

-- LL

SpacerHey, Scripting Guy! AnswerScript Center

Hey, LL. Here’s a piece of trivia for you. Originally, the Beatles’ classic Yesterday was titled Scrambled Eggs. (Start singing the song, but instead of singing “Yesterday” sing “Scrambled eggs.”) Before the group recorded the song, however, Paul wrote some lyrics and, in the process, changed the name as well. The rest, as they say, is history.

No doubt your next question is this: did Paul McCartney use a script to change the title of Scrambled Eggs? To tell you the truth, we don’t know; we always mean to ask Paul that, but every time we get together it seems like something comes up and we forget to ask. However, there’s no doubt that he could have used a script like this one to change the title:

Set objPlayer = CreateObject("WMPlayer.OCX" )

Set objMediaCollection = objPlayer.MediaCollection
Set objTempList = objMediaCollection.getByName("Scrambled Eggs")

Set objSong = objTempList.Item(0)
objSong.setItemInfo "Name", "Yesterday"

Before we go any further we should point out that this script changes the song title only as far as Windows Media Player is concerned. When you view your song list in Windows Media Player the song formerly known as Scrambled Eggs will now appear as Yesterday. However, this script doesn’t change the .WMA file itself: the file name remains as-is, and if you right-click the file and look at the Summary Properties the title will still show up as Scrambled Eggs. Unfortunately, we don’t know of any way to change the Title property of the file itself; the best we can do is change the way the song title appears in Windows Media Player.

Note. What’s that? You didn’t even know that you could script Windows Media Player? You guys haven’t been to Dr. Scripto’s Fun Zone have you?

If you’re OK with just changing the song as it appears in Windows Media Player, well then, read on. As you can see, our script begins by creating an instance of the WMPlayer.OCX object; this is simply the object that provides programmatic access to Windows Media Player. We then use these two lines of code to bind to the Windows Media Player media collection and to return a list of all the songs that have the title Scrambled Eggs:

Set objMediaCollection = objPlayer.MediaCollection
Set objTempList = objMediaCollection.getByName("Scrambled Eggs")

And yes, we do need to return a collection: that’s because Windows Media Player actually allows you to have multiple songs with the same title. We’re going to assume that you’ve given all your songs unique titles; that enables us to take a little bit of a shortcut when binding to the song and changing your title. If you do have multiple songs with the title Scrambled Eggs then you can use this modified script to change the title for each of those songs:

Set objPlayer = CreateObject("WMPlayer.OCX" )

Set objMediaCollection = objPlayer.MediaCollection
Set objTempList = objMediaCollection.getByName("Scrambled Eggs")

For i = 0 to objTempList.Count - 1
    Set objSong = objTempList.Item(i)
    objSong.setItemInfo "Name", "Yesterday"
Next

Now, back to the script that assumes you have only one song named Scrambled Eggs. If that���s the case then we need only this line of code to bind directly to the single song with that title (completely bypassing the For Next loop we had to use in the preceding script):

Set objSong = objTempList.Item(0)

Once we’ve made the connection, changing the title is as simple as using the setItemInfo method to change the song Name to Yesterday:

objSong.setItemInfo "Name", "Yesterday"

The rest, as they say, is history.

Incidentally, the Scripting Guys also like the name Scrambled Eggs better; if nothing else, it goes nicely with the song I Am the Walrus (“I am the egg man, they are the egg men”). But the Beatles never asked the Scripting Guys for their opinion on this one. We just hope things worked out OK for them even without our help.