在Finder中选择多个文件

时间:2013-12-05 04:55:49

标签: applescript

在我的AppleScript中,我有一个函数,它接受一个选定的文件并将其路径写入xml文件。如果选择了一个文件夹,我可以创建一个包含所包含文件的列表并将其发送到我的函数。但是,如果我选择多个取景器项目(通过移位点击),无论是文件还是文件夹,我都无法向该功能发送任何内容。

这是我从Finder获取文件的部分

tell application "Finder"
  set myPath to the selection
end tell
--if multiple files selected
if (count of myPath) is greater than 1 then
    set fileList to every item of myPath
    repeat with i in fileList
        if (isDirectory(i)) then
        else
            myBigLoop(initialSuccess, i, watchFolder)
        end if
    end repeat
else if (isDirectory(myPath)) then
    submitFolder(myPath, watchFolder)
else
    set isFolder to false
    set initialSuccess to true
    myBigLoop(initialSuccess, myPath, watchFolder)
end if

on myBigLoop(initialSuccess, fileList, watchFolder)
    repeat with myPath in fileList      
        if initialSuccess then          
            tell application "Finder"
                set myFilename to myPath as alias
                set myPath to the folder of myFilename              
                set myPath to myPath as string
                set myFilename to name of myFilename
                display dialog myFilename
            end tell
        end if --end InitialSuccess
    end repeat
end myBigLoop

on isDirectory(someItem) -- someItem is a file reference
    set filePosixPath to quoted form of (POSIX path of (someItem as alias))
    set fileType to (do shell script "file -b " & filePosixPath)
    if fileType ends with "directory" then return true
    return false
end isDirectory

on submitFolder(myPath, watchFolder)
    set isFolder to true
    set initialSuccess to true
    set fileList to item 1 of myPath
    set fileList to get every file of fileList
    set numFiles to count fileList
    if numFiles is equal to 0 then
        display dialog "There were no files in that folder."
        return false
    end if
    myBigLoop(initialSuccess, fileList, watchFolder)
end submitFolder

1 个答案:

答案 0 :(得分:0)

我相信你应该扩展Finder告诉结构,因为你以后还在使用文件和文件夹:

tell application "Finder"
    set myPath to the selection
  --if multiple files selected
    if (count of myPath) is greater than 1 then
        set fileList to every item of myPath
        repeat with i in fileList
            if (isDirectory(i)) then
            else
                myBigLoop(initialSuccess, i, watchFolder)
            end if
        end repeat
    else if (isDirectory(myPath)) then
        submitFolder(myPath, watchFolder)
    else
        set isFolder to false
        set initialSuccess to true
        myBigLoop(initialSuccess, myPath, watchFolder)
    end if
end tell