Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

iTunes change file location

Status
Not open for further replies.

deleyd

Programmer
Dec 22, 2010
3
US
I'm trying to write a test script that sets the file location of a music file in iTunes. It doesn't generate any errors, but when I check it in iTunes the file location hasn't been changed. How do I make this work?

Code:
Set iTunesApp = CreateObject("iTunes.Application")
Set objPlaylist = iTunesApp.LibraryPlaylist
Set colTracks = objPlaylist.Tracks

For Each objTrack in colTracks
    Wscript.Echo "Name: " & objTrack.Name
    Wscript.Echo "Album: " & objTrack.Album
    Wscript.Echo "Artist: " & objTrack.Artist
    strLocation = objTrack.Location
    Wscript.Echo "Location: " & strLocation
    Wscript.Echo "Kind: " & objTrack.Kind
    if objTrack.Kind = 1 then
      Wscript.Echo "Kind is 1"
      strLocation = "C:\Users\deleyd\Music\iTunes\iTunes Music\Music\Tangerine Dream\Logos - Live At The Dominion - London 19\01 Logos Part OneB.mp3"
  EXIT FOR
Next
 
If your "if... then" statement has multiple lines to execute after, you need "if ... then ... end if" construction. Even that, you still need to actually set the location, assuming .Location is read-write.
[tt]
Set iTunesApp = CreateObject("iTunes.Application")
Set objPlaylist = iTunesApp.LibraryPlaylist
Set colTracks = objPlaylist.Tracks

For Each objTrack in colTracks
Wscript.Echo "Name: " & objTrack.Name
Wscript.Echo "Album: " & objTrack.Album
Wscript.Echo "Artist: " & objTrack.Artist
strLocation = objTrack.Location
Wscript.Echo "Location: " & strLocation
Wscript.Echo "Kind: " & objTrack.Kind
if objTrack.Kind = 1 then
Wscript.Echo "Kind is 1"
strLocation = "C:\Users\deleyd\Music\iTunes\iTunes Music\Music\Tangerine Dream\Logos - Live At The Dominion - London 19\01 Logos Part OneB.mp3"
[red]objTrack.Location=strLocation[/red] 'whether it will do what needed, I've no idea.
EXIT FOR
[red]end if[/red]
Next
[/tt]
 
I get "Invalid procedure call or argument" error for the line
Code:
objTrack.Location=
 
Very well then, where is the documentation? Where is it the line you think you set the location or where do you intend to use strLocation?
 
The iTunes SDK says:
HRESULT Location ([out, retval] BSTR *location)
Returns the full path to the file represented by this track.
and it later says:
HRESULT Location ([in] BSTR location)
Set the full path to the file represented by this track. iTunes will not move or copy any existing file from the track's current location to the new location, the full path must point to an existing file that is playable by iTunes. Attempting to set the location of a track on CD will always fail with E_INVALIDARG.
I've tried various forms of
Code:
objTrack.Location=strLocation
objTrack.Location="C:\Users\deleyd\Music\test.mp3"
I've had success using the AutoHotkey scripting language with the line:
Code:
iTunesApp.LibraryPlaylist.Tracks.Item(1).Location := "C:\Users\deleyd\Music\iTunes\test.mp3"
so I've switched to using AutoHotkey for now, but am curious how this would be done in VBScript.
[small]( — free scripting language)[/small]
 
If that can, I don't see why vbs can't. Try this form of the loop.
[tt]
For i=colTracks.count-1 to 0 step -1
set objTrack=colTracks.item(i)
'continue the same
Next
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top