2010-10-02 27 views
1

我添加到iTunes中的腳本文件,試圖添加不支持的類型,如JPG/TXT文件的/ .thumb等AppleScript的選擇一定的延伸

我想成爲一個更具體一點與下面的代碼,只有選擇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 

回答

2

我不知道你在與第一線做什麼。但是如果你可以強制這個文件路徑到一個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中列出的擴展名的文件。

+1

謝謝你的工作,但我認爲thisFilePath始終是unicode文本字符串,所以沒有擴展屬性。我想我需要編寫一個解析函數來獲取擴展名,或者讓「tell application」Finder將fPaths設置爲((作爲Unicode文本的整個內容的文件)的段落)「返回文件對象列表,而不是一個文本數組/段落 – 2010-10-05 07:35:07