→ “Perry Como With Mitchell Ayres And His Orchestra”[/code]
In AppleScript, the clean solution is to define a bunch of interchangeable script objects, each of which is responsible for getting one of the properties you need in response to a common command (getProp(trackRef) in the example code below). You can then assign those objects to variables, pass them around your program, etc. as normal, and any time you want to get the value of a track property, just send a ‘getProp’ command with a reference to the desired track:
using terms from application "iTunes"
get name of trackRef
get artist of trackRef
get album of trackRef
end using terms from
tell application "iTunes" to set myTrack to current track
set x to GetName
--> "Papa Loves Mambo"
set x to GetArtist
--> "Perry Como With Mitchell Ayres And His Orchestra"
It’s a rather verbose solution as you can see, but it’s fast and reliable. The dirty alternative is to hack it using code generation a-la StefanK’s suggestion, although the run script command is relatively slow and code generation can easily introduce bugs/security holes if you’re not careful.