0

这里有点问题。我正在尝试使特定的文件夹操作起作用,但是无论我做什么,我似乎都无法使其正常工作。我的所有其他文件夹操作都按预期工作,即使是我自己编写的 AppleScript 也是如此。但是,不是这个。继承人的代码:

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”处理程序并使用“选择文件”对话框运行脚本,它可以完美运行,正如预期的那样。因此,从理论上讲,代码本身没有任何问题。我已经检查了“/Library/Scripts/Folder Action Scripts”中文件的文件权限,这就是我得到的:

-rwxr-xr-x   1 root  wheel  20758 Sep  2 14:43 add - copy based on type.scpt

在我看来,这完全正确。(我必须在保存文件后手动设置这些权限。)

关于出了什么问题的任何想法?

- 啊

4

1 回答 1

0

我的猜测是您希望 added_items 是文件列表,因此您使用重复循环。我怀疑也许当只添加一个文件时它不是一个列表,因此重复循环不起作用。因此,我建议检查 added_items 的类并相应地进行。因此,请尝试将脚本的顶部更改为此...

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
于 2012-09-02T23:38:11.720 回答