Search code examples
comitunesautohotkeyitunes-sdk

Retrieve an iTunes Track object from its high/low persistent ID


I'm trying to retrieve a track object from its persistent ID using AutoHotkey (v1.1) and iTunes Windows 11. The script works well until I try to use the ItemByPersistentID method.

objITunesunesApp := ComObjCreate("iTunes.Application")
objITunesLibrary := objITunesunesApp.Sources.Item(1)
objITunesPlaylist := objITunesLibrary.Playlists.Item(1)
objITunesTrack := objITunesPlaylist.Tracks.Item(1)

; Test if objects are OK
MsgBox, % objITunesTrack.Name ; Display the song name - OK

; Get high and low IDs
intIDHigh := objITunesunesApp.ITObjectPersistentIDHigh(objITunesTrack)
intIDLow := objITunesunesApp.ITObjectPersistentIDLow(objITunesTrack)
MsgBox, %intIDHigh% %intIDLow% ; Display: "-1071797520 -947434212" OK

; Try to get the track again using the persistent IDs
objTrackByID := objITunesLibrary.ItemByPersistentID(intIDHigh, intIDLow)
; Error:  0x80020006 - Name unknown
; Specifically: ItemByPersistentID

MsgBox, % "objTrackByID.Name: " . objTrackByID.Name ; name empty

Am I calling ItemByPersistentID the right way? Thanks.


Solution

  • Just found the error in the original script:

    objTrackByID := objITunesPlaylist.Tracks.ItemByPersistentID(intIDHigh, intIDLow)
    

    ItemByPersistentID is a method of Tracks collections.