2013-12-05 2 views
1

В моем applescript у меня есть функция, которая берет выбранный файл и записывает свой путь в xml-файл. Если выбрана папка, я могу создать список с содержащимися файлами и отправить его моей функции. Однако, если я выберу несколько элементов искателя (с помощью нажатия сдвига), будь то файлы или папки, я не могу ничего передать функции.Выбор нескольких файлов в Finder

здесь та часть, где я получить файлы из 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 
+0

Пожалуйста, включите и ваши обработчики. – adayzdone

+0

Хорошо, я добавил их. @adayzdone – gneek

ответ

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 
+0

Спасибо @Mark, но я получаю такое же поведение, расширяя подсказку. Ошибка «не может вносить ожидаемый тип». Я попробовал 'set i to i as alias', но это не работает. – gneek

+0

Извините @gneek Я изучу, если никто другой не отправит хороший ответ передо мной. – Mark

Смежные вопросы