Macos Can';无法使特定文件夹操作正常工作

Macos Can';无法使特定文件夹操作正常工作,macos,applescript,directory,Macos,Applescript,Directory,这里有点问题。我正试图让一个特定的文件夹操作正常工作,但无论我做什么,我似乎都无法让它正常工作。我的所有其他文件夹操作都按预期工作,即使是我自己编写的。但是,不是这个。代码如下: on adding folder items to this_folder after receiving added_items --set added_items to choose file with multiple selections allowed processItems(added_items) e

这里有点问题。我正试图让一个特定的文件夹操作正常工作,但无论我做什么,我似乎都无法让它正常工作。我的所有其他文件夹操作都按预期工作,即使是我自己编写的。但是,不是这个。代码如下:

on adding folder items to this_folder after receiving added_items
--set added_items to choose file with multiple selections allowed
processItems(added_items)

end adding folder items to

on processItems(added_items)

set imageTypesList to {"JPEG image", "Portable Network Graphics image", "Windows bitmap image", "Graphics Interchange Format image", "Adobe Photoshop File", "TIFF Image"}

set audioTypesList to {"MP3 audio", "AIFF-C audio", "Waveform audio"}
set videoTypesList to {"Video-MPEG4", "MPEG-4 File", "Video-MPEG2", "Video-MPEG", "AVI", "Matroska Video File"}
set fontTypesList to {"TrueType font", "PostScript® Type 1 outline font", "Font Suitcase"}
set docsTypesList to {"Portable Document Format (PDF)", "Scrivener Project", "Microsoft Word 97 - 2004 document", "Rich Text Document", "Plain Text Document", "CSV Document", "Pages Publication", "Keynote Presentation"}
set epubTypesList to {"epub", "Kindle Document", "iBooks Author Template", "iBooks Author Book"}
set archTypesList to {"ZIP archive", "tar archive", "rar archive", "Tar Gzip Archive"}
set diskTypesList to {"Installer package", "Disk Image"}
set execTypesList to {"Unix Executable File"}
set appsTypesList to {"Application (32-bit)", "Application"}
set iconTypesList to {"Apple Icon Image", "Icon Container", "Windows Icon Image"}
set otherTypesList to {"XTorrent File"}
set scriptTypesList to {"Compiled OSA Script"}
set openTypesList to {"Chromium Extra", "Action", "RapidWeaver Theme", "Mac OS X Preference Pane"}

set uberList to imageTypesList & audioTypesList & videoTypesList & fontTypesList & docsTypesList & ¬
    epubTypesList & archTypesList & diskTypesList & execTypesList & appsTypesList & iconTypesList & ¬
    otherTypesList & scriptTypesList & openTypesList

set imagesFolder to "Technomage:Users:andyhainline:Downloads:Images" as alias
set appsFolder to "Technomage:Users:andyhainline:Downloads:Apps" as alias
set archivesFolder to "Technomage:Users:andyhainline:Downloads:Archives" as alias
set epubFolder to "Technomage:Users:andyhainline:Downloads:eBooks" as alias
set fontsFolder to "Technomage:Users:andyhainline:Downloads:Fonts" as alias
set docsFolder to "Technomage:Users:andyhainline:Downloads:PDFs and Docs" as alias
set diskFolder to "Technomage:Users:andyhainline:Downloads:Installers and Disk Images" as alias
set iconFolder to "Technomage:Users:andyhainline:Downloads:Icons" as alias
set audioFolder to "Technomage:Users:andyhainline:Downloads:Audio" as alias
set videoFolder to "Technomage:Users:andyhainline:Downloads:Video" as alias
set otherFolder to "Technomage:Users:andyhainline:Downloads:Torrent Files" as alias
set miscFolder to "Technomage:Users:andyhainline:Downloads:Miscellanious" as alias
set scriptFolder to "Technomage:Users:andyhainline:Downloads:AppleScripts and Automator Stuff" as alias
set execFolder to "Technomage:Users:andyhainline:Downloads:Run From Here" as alias

tell application "Finder"
    repeat with anItem in added_items
        if (kind of anItem) is in imageTypesList then
            move file anItem to imagesFolder with replacing
        else if (kind of anItem) is in audioTypesList then
            move file anItem to audioFolder with replacing
        else if (kind of anItem) is in videoTypesList then
            move file anItem to videoFolder with replacing
        else if (kind of anItem) is in fontTypesList then
            move file anItem to fontsFolder with replacing
        else if (kind of anItem) is in docsTypesList then
            move file anItem to docsFolder with replacing
        else if (kind of anItem) is in epubTypesList then
            move file anItem to epubFolder with replacing
        else if (kind of anItem) is in archTypesList then
            move file anItem to archivesFolder with replacing
            open (path to archiveFolder & (name of file anItem))
        else if (kind of anItem) is in diskTypesList then
            move file anItem to diskFolder with replacing
        else if (kind of anItem) is in execTypesList then
            move file anItem to appsFolder with replacing
        else if (kind of anItem) is in webTypesList then
            move file anItem to docsFolder with replacing
        else if (kind of anItem) is in iconTypesList then
            move file anItem to iconFolder with replacing
        else if (kind of anItem) is in otherTypesList then
            move file anItem to otherFolder with replacing
        else if (kind of anItem) is in scriptTypes then
            move file anItem to scriptFolder with replacing
        else if (kind of anItem) is in openTypes then
            delay 10
            open anItem
            move file anItem to miscFolder
        else if (kind of anItem is "Folder") then
            set folderFiles to get every file of folder anItem
            processItems(folderFiles)
        end if
    end repeat
end tell
结束处理项目

正如你所见,这相当复杂。请注意:如果我在开始时注释掉“on”处理程序,并使用“choosefiles”对话框运行脚本,那么它会很好地工作,正如预期的那样。因此,从理论上讲,代码本身没有什么问题。我已在“/Library/Scripts/Folder Action Scripts”中检查了该文件的文件权限,我得到的结果如下:

-rwxr-xr-x   1 root  wheel  20758 Sep  2 14:43 add - copy based on type.scpt
在我看来,这是完全正确的。(保存文件后,我必须手动设置这些权限。)

有什么问题吗


--A.H.

我的猜测是,您希望添加的项目是一个文件列表,因此使用重复循环。我怀疑当只添加一个文件时,它不是列表,因此重复循环不起作用。因此,我建议检查添加的_项的类别,并相应地进行操作。所以试着把脚本的顶部改成这个

on adding folder items to this_folder after receiving added_items
    --set added_items to choose file with multiple selections allowed
    if (class of added_items) is list then
        processItems(added_items)
    else
        processItems({added_items}) -- here we make it a list so the repeat loop works
    end if
end adding folder items to