First - I’m very new to applescript & am very confused:
This works (from within a loop)
repeat while track_index ≤ max_index
set tr to track track_index of playlist playlist_name
set album_artist to album artist of tr
...
end
Groovy.
This however, does not:
on mt(track)
set album_artist to album artist of track
end
repeat while track_index ≤ max_index
set tr to track track_index of playlist playlist_name
mt(tr)
....
end
I get an error when I try to compile the above code - the error is on the line in the ‘mt’ function.
What’s goofy is this works:
on mt(track)
set album to album of track
end
repeat while track_index ≤ max_index
set tr to track track_index of playlist playlist_name
mt(tr)
....
end
So basically as long as the record name does not have a space in it in the ‘mt’ function it works - any record with a space in its name (‘album artist’, ‘bit rate’ &c) barfs the compile
Ack! Any ideas??? I’ve tried quoting & {}'s - & while the error messages from the compiler changes it just doesn’t like record names with spaces in them within a called function that takes a ‘track’.
I have learned A LOT from reading the various posts within this forum for thanks!
Model: powerbook g4
AppleScript: 1.10.7
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)
Let me answer my own question for completeness - if I wrap the function within a ‘using terms from iTunes/end using term from’ block it’s all good…
Mark
For the compiler to be able to understand code belonging to iTunes, the code has to be in a ‘tell application “iTunes”’ block. Presumably, the part of your code that isn’t in the mt() handler is in such a block in your full script.
But inside a handler, the code isn’t physically inside the tell block, so you need another tell block in the handler to ensure that the term ‘album artist’ is understood.
on mt(track)
tell application "iTunes"
set album_artist to album artist of track
end tell
end mt
In the above case, ‘track’ is also an iTunes keyword, so it’s not a good idea to use it as the name of the parameter variable. Some variation like ‘the_track’ or ‘my_track’ would be better.
Since the call to the handler is in the tell block in the main part of the script, you’ll need to make clear that the call belongs to the script, not to iTunes, otherwise iTunes itself will try to understand it and fail with an error. The simplest method is to put ‘my’ in front of the handler call.
on mt(the_track)
tell application "iTunes"
set album_artist to album artist of the_track
end tell
end mt
tell application "iTunes"
-- ....
repeat while track_index ≤ max_index
set tr to track track_index of playlist playlist_name
my mt(tr)
--....
end repeat
-- ....
end tell
‘Using terms from’ is for specialised use and isn’t the right answer in this case.