Give this a try, playlist_id should be the value you are looking for.
tell application "iTunes"
set TheLibraryRef to (every user playlist)
try
set thetest to (item 1 of TheLibraryRef) as string
on error errMsg
set playlist_id to word 6 of errMsg
end try
end tell
It’s a bit fiddly. AppleScript doesn’t allow you to look inside reference objects, so you can’t get the id from the reference itself. Fortunately, iTunes objects have an undocumented ‘id’ property which you can use to get their id numbers; unfortunately, iTunes’ dictionary doesn’t define an ‘id’ keyword [1], which means that AppleScript can’t compile the following code:
tell app "iTunes"
set playlistRef to user playlist id 7881 of source id 39
set playlistID to id of playlistRef -- typically cryptic syntax error occurs here
end tell
You can get around this by making sure the ‘id’ keyword appears outside the application tell block:
tell app "iTunes"
set playlistRef to user playlist id 7881 of source id 39
end tell
set playlistID to id of playlistRef --> 7881
A bit messy, but it works. (Modulo the usual caveats of using undocumented features, of course.)
HTH
[1] Feel free to file a bug report with Apple on this.
There is an ‘id’ keyword defined in AppleScript’s dictionary on 10.4 (older OSes I don’t know about), although it doesn’t do anything useful within AppleScript itself. The second example compiles fine here. If it won’t compile for you, use the raw form:
set playlistID to «property ID » of playlistRef
(Note: there should be not one but two spaces after ‘ID’ in the above code; the forum software doesn’t preserve them properly.)