views:

24

answers:

1

My add to itunes script is trying to add files of unsupported types such as jpg/txt/.thumb etc

I would like to be a bit more specific with the below code to only select mp3 & m4a

tell application "Finder" to set fPaths to paragraphs of ((files of entire contents of iTunesFolder) as Unicode text)

 repeat with thisFilePath in fPaths
    --processing code goes here
    -- maybe I need an if file extension is in... type condition?

 end repeat
+1  A: 

I’m not sure what you’re doing with that first line. But if you can coerce thisFilePath into a Finder item, you should be able to get the extension. The property is called name extension. I’ve tested this with the files on my desktop:

copy {"pdf", "scpt"} to validExtensions

tell application "Finder" to set fPaths to files of desktop

repeat with thisFilePath in fPaths
    if name extension of thisFilePath is in validExtensions then
        display dialog thisFilePath as string
    end if
end repeat

It will display only those files that specifically have an extension listed in validExtensions.

Jerry Stratton
Thanks that would of worked but I think thisFilePath is always unicode text string so has no extension property. I think I either need to write a parsing function to get the extention or make "tell application "Finder" to set fPaths to paragraphs of ((files of entire contents of iTunesFolder) as Unicode text)" return a list of file objects rather than a text array/paragraph
Keegan's hairstyle 82