Applescript выбор файлов определенного расширения - PullRequest
0 голосов
/ 02 октября 2010

Мой скрипт добавления в itunes пытается добавить файлы неподдерживаемых типов, таких как jpg / txt / .thumb и т. Д.

Я хотел бы быть более конкретным с приведенным ниже кодом, чтобы выбрать только 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 Ответ

2 голосов
/ 03 октября 2010

Я не уверен, что вы делаете с этой первой строкой.Но если вы можете привести thisFilePath к элементу Finder, вы сможете получить расширение.Свойство называется расширение имени .Я проверил это с файлами на рабочем столе:

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

. Он будет отображать только те файлы, которые имеют расширение, указанное в validExtensions .

.
...