开发者

Applescript selecting files of a certain extension

开发者 https://www.devze.com 2023-01-18 23:02 出处:网络
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

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开发者_Python百科 if file extension is in... type condition?

 end repeat


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消