Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Applescript > Re: iTunes: Sim...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 1563 of 1647
Post > Topic >>

Re: iTunes: Simple question: Why doesn't this work?

by Jolly Roger <jollyroger@[EMAIL PROTECTED] > Jan 27, 2008 at 09:36 AM

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
 




 3 Posts in Topic:
iTunes: Simple question: Why doesn't this work?
biz@[EMAIL PROTECTED]   2008-01-27 03:38:22 
Re: iTunes: Simple question: Why doesn't this work?
jb@[EMAIL PROTECTED] (Jo  2008-01-27 14:27:20 
Re: iTunes: Simple question: Why doesn't this work?
Jolly Roger <jollyroge  2008-01-27 09:36:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 12:51:08 CDT 2008.