In article
<359a9edb-6f80-4e44-808b-81c53b755dc7@[EMAIL PROTECTED]
>,
biz@[EMAIL PROTECTED]
wrote:
> set x to track 1 of library playlist 1 whose name is "Cry Freedom"
Don't specify track number 1, because you don't know the actual track
number of "Cry Freedom".
Also, it'd be cleaner to use a tell block for the library playlist, like
so:
-- begin script
tell app "iTunes"
tell library playlist 1
set x to the track whose name is "Cry Freedom"
end tell
end tell
-- end script
> set x to track 1 of library playlist 1 whose track location contains
> "Cry Freedom"
According to the iTunes dictionary, "location" is an alias to the file
on disk. Doing a textual operation on it will coerce it to a full path.
But you just want the filename part of the path - not the whole path. So
you'll need to get the filename from the path. There are a couple ways
to do this:
1. (faster) Use a sub handler to parse the filename from the textual
full path:
-- begin script
tell application "iTunes"
tell library playlist 1
set foundTracks to the tracks whose name is "Cry Freedom"
repeat with nextTrack in foundTracks
set trackLocation to nextTrack's location
set fileInfo to info for trackLocation
set fileName to my FilenameFromPath(trackLocation)
if fileName contains "Cry Freedom" then
beep -- got a match
end if
end repeat
end tell
end tell
on FilenameFromPath(thePath)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set pathAsList to text items of (thePath as text)
if the last character of (thePath as text) is ":" then
set idx to -2 -- (the number of text items in thePath) - 1
else
set idx to -1
end if
set fileName to item idx of pathAsList
set AppleScript's text item delimiters to oldDelimiters
return fileName
end FilenameFromPath
-- end script
2. (slower) Use the "info for" command (from the Standard Additions
dictionary):
-- begin script
tell application "iTunes"
tell library playlist 1
set foundTracks to the tracks whose name is "Cry Freedom"
repeat with nextTrack in foundTracks
set trackLocation to nextTrack's location
set fileInfo to info for trackLocation
set fileName to fileInfo's name
if fileName contains "Cry Freedom" then
beep -- got a match
end if
end repeat
end tell
end tell
-- end script
Have you examined iTunes dictionary? If not, you should. To view it, run
Script Editor, from the Script Editor menu bar, choose File > Open
Dictionary, then select iTunes. There's lots of useful information in
application dictionaries.
--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.
JR


|