I have this modified code that should allow me to set the “grouping” category in iTunes. The script is supposed to get the YEAR, the TRACKNUM, the ARTIST, and the ALBUM from the mp3Tags and then write it in order to the “grouping” category. This is so I can sort my compelations in order. My only problem is that the script cant seem to get the track number properly
Please help! It would really be appreciated.
tell application “iTunes”
if selection is not {} then
repeat with this_track in selection
set this_year to (get this_track’s year)
set this_tracknum to (get this_track’s track)
set this_artist to (get this_track’s artist)
set this_album to (get this_track’s album)
if this_year > 0 then
set this_track’s grouping to this_year & “,” & this_tracknum & “,” & this_artist & “,” & this_album
else
set this_track’s grouping to this_year & “,” & this_tracknum
end if
end repeat
else
display dialog “Select some tracks first…” buttons {“Cancel”} default button 1 with icon 2 giving up after 15
end if
end tell
Perhaps you are looking for [track number]?
tell application "iTunes"
if selection is not {} then
repeat with this_track in selection
set this_year to (get this_track's year)
set this_tracknum to (get this_track's track number)--See iTunes Applescript dictionary for track number definition
set this_artist to (get this_track's artist)
set this_album to (get this_track's album)
if this_year > 0 then
set this_track's grouping to this_year & "," & this_tracknum & "," & this_artist & "," & this_album
else
set this_track's grouping to this_year & "," & this_tracknum
end if
end repeat
else
display dialog "Select some tracks first..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
end if
end tell
I changed the “track number” object exactly like you have it and it still gives me an error.
It says “can’t make data into the expected type”
Do I have to define it as somthing? All my scripting friends are stumped! Please help!
Right. Sorry about that, I should have tested it first. The variables for track number and year are numbers; they need to be coerced into strings:
tell application "iTunes"
if selection is not {} then
repeat with this_track in selection
set this_year to (this_track's year)
set this_tracknum to (this_track's track number) --See iTunes Applescript dictionary for track number definition
display dialog this_tracknum
set this_artist to (this_track's artist)
set this_album to (this_track's album)
if this_year > 0 then
set this_track's grouping to ((this_year as string) & "," & (this_tracknum as string) & "," & this_artist & "," & this_album)
else
set this_track's grouping to this_year & "," & this_tracknum
end if
end repeat
else
display dialog "Select some tracks first..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
end if
end tell
Thanks alot Craig! It worked very well. The grouping output was perfectly formatted.
There is one thing that is wierd, when I execute the script (on a single file or a batch) it gives me a dialog box with the track number and an ok button after each file it completes the grouping for. It makes you press enter after every file… is there a way to change this so it just does every file in the batch and at the end it just says completed or says nothing?
Thanks in advance for your time.
Sorry again, I forgot to remove one line I had used during testing:
tell application "iTunes"
if selection is not {} then
repeat with this_track in selection
set this_year to (this_track's year)
set this_tracknum to (this_track's track number) --See iTunes Applescript dictionary for track number definition
set this_artist to (this_track's artist)
set this_album to (this_track's album)
if this_year > 0 then
set this_track's grouping to ((this_year as string) & "," & (this_tracknum as string) & "," & this_artist & "," & this_album)
else
set this_track's grouping to this_year & "," & this_tracknum
end if
end repeat
else
display dialog "Select some tracks first..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
end if
end tell
FANTASTIC. You are the best! 5 Stars.