2009-11-11 58 views
1
文件類型

這個問題並不侷限於誰知道AppleScript的,如果你這樣做可可等,你應該知道這個問題的答案的人:限制對液滴

我做液滴在的AppleScript壓縮JavaScript文件,顯然,我只希望JavaScript文件被允許進入腳本。有任何想法嗎?

非常感謝。

回答

2
property kJavascriptExtension : "js" 
property pValidFileList : {} 

on open of theFiles -- Executed when files are dropped on the script 

    set fileCount to (get count of items in theFiles) 

    repeat with thisFile from 1 to fileCount 
     set theFile to item thisFile of theFiles 
     set theFileAlias to theFile as alias 

     tell application "Finder" 
      set fileInfo to info for theFileAlias 
      set fileName to name of fileInfo 
     end tell 

     set javascriptFileFound to isJavascriptFile(fileName) of me 

     if (javascriptFileFound) then 
      set end of pValidFileList to theFile 
     end if 
    end repeat 

    display dialog "pValidFileList = " & pValidFileList 
    -- do something with your files here 
end open 

on isJavascriptFile(theFilename) -- (theFilename as string) as boolean 
    set AppleScript's text item delimiters to "." 
    set fileNameList to every text item of theFilename 
    set AppleScript's text item delimiters to "" 

    try 
     set theFileExtension to item 2 of fileNameList as string 
    on error 
     return false 
    end try 

    if theFileExtension is kJavascriptExtension then 
     return true 
    end if 

    return false 
end isJavascriptFile 
+0

這太好了!我預計某種Info.plist屬性,但這似乎更簡單。 – 2009-11-11 14:34:32

相關問題