Applescript创建监视文件夹,并在已删除的文件和已创建的文件夹中移动文件

Applescript创建监视文件夹,并在已删除的文件和已创建的文件夹中移动文件,applescript,Applescript,我已经有一两年没有使用Applescript了,所以我有点生疏了。下面是我目前使用的脚本遇到的问题,以及我希望脚本执行但无法实现的一些附加项目 问题: 如果要在数据处理文件夹中创建子文件夹,新名称将为{“Data In”,“Data Released”};这通常意味着我在尝试这样做时没有定义变量 我想所有的文件和文件夹内的下降文件夹移动到机构文件夹下的艺术品文件夹;如果我尝试不执行上述#1,我仍然会收到一个错误,说明操作无法完成 以下是我迄今为止的脚本,任何和所有的帮助将不胜感激 on

我已经有一两年没有使用Applescript了,所以我有点生疏了。下面是我目前使用的脚本遇到的问题,以及我希望脚本执行但无法实现的一些附加项目

问题:

  • 如果要在数据处理文件夹中创建子文件夹,新名称将为{“Data In”,“Data Released”};这通常意味着我在尝试这样做时没有定义变量
  • 我想所有的文件和文件夹内的下降文件夹移动到机构文件夹下的艺术品文件夹;如果我尝试不执行上述#1,我仍然会收到一个错误,说明操作无法完成
  • 以下是我迄今为止的脚本,任何和所有的帮助将不胜感激

        on adding folder items to this_folder after receiving added_items
    -- added_items is a _list_ of the items just added, even when there's only one. Deal with each item in turn.
    repeat with this_item in added_items
        tell application "Finder"
            -- 'item this_item' gets a Finder reference to the item so that its class can be determined.
            if (class of item this_item is folder) then
                try
                    -- Make new folders in this dropped folder.
                    set client_files_folder to (make new folder in this_item with properties {name:"Artwork"})
                    make new folder in client_files_folder with properties {name:"AGENCY"}
                    make new folder in client_files_folder with properties {name:"EXPORT_TO_XMPIE"}
                    make new folder in client_files_folder with properties {name:"XMPIE"}
                    make new folder in this_item with properties {name:"Data Processing"}
                    make new folder in this_item with properties {name:"Imaging_Laser"}
                    make new folder in this_item with properties {name:"Production Report"}
                    make new folder in this_item with properties {name:"Program Plan"}
    
                    -- Move the following items from the dropped folder to the just-created "AGECNY" folder.
                    move {every folder of this_item} to client_files_folder
    
                on error errMsg
                    display dialog errMsg
                end try
            end if
        end tell
    end repeat
    end adding folder items to
    
    ======更新====== 我可以创建子文件夹,但现在无法将文件夹移动到正确的子文件夹中。你能提供一些指导吗?请参阅下面我的最新脚本:

        on adding folder items to this_folder after receiving added_items
    -- added_items is a _list_ of the items just added, even when there's only one. Deal with each item in turn.
    repeat with this_item in added_items
        tell application "Finder"
            -- 'item this_item' gets a Finder reference to the item so that its class can be determined.
            if (class of item this_item is folder) then
                try
                    -- Make new folders in this dropped folder.
                    set ART_Folder to (make new folder in this_item with properties {name:"Artwork"})
                    set Data_Folder to (make new folder in this_item with properties {name:"Data Processing"})
                    set Agency_Folder to (make new folder in ART_Folder with properties {name:"AGENCY"})
                    make new folder in ART_Folder with properties {name:"EXPORT_TO_XMPIE"}
                    make new folder in ART_Folder with properties {name:"XMPIE"}
                    make new folder in Data_Folder with properties {name:"Data In"}
                    make new folder in Data_Folder with properties {name:"Data Released"}
                    make new folder in this_item with properties {name:"Imaging_Laser"}
                    make new folder in this_item with properties {name:"Production Report"}
                    make new folder in this_item with properties {name:"Program Plan"}
    
                    -- Move the items from the dropped folder to the just-created "AGECNY" folder.
                    move folders in this_item to Agency_Folder
    
                on error errMsg
                    display dialog errMsg
                end try
            end if
        end tell
    end repeat
    end adding folder items to
    
    =======瓦迪安在删除前提供的答案=========

    我在运行macOS Sierra(10.12.2)的系统上尝试了以下操作,但无法在我的系统上运行

    *

    操作无法完成的主要问题是因为您 将移动所有项目,包括当前创建的新项目 文件夹,而不仅仅是创建 文件夹。shell命令mkdir可以在一个文件夹中创建文件夹层次结构 线路。这比使用Finder更有效。试试这个

    *


    在对stackexchange及其各种贡献者进行了大量测试和审查之后,我能够将以下代码组合在一起,以实现我在文章中概述的目标

    on adding folder items to this_folder after receiving added_items
    -- added_items is a _list_ of the items just added, even when there's only one. Deal with each item in turn.
    repeat with this_item in added_items
        tell application "Finder"
            -- 'item this_item' gets a Finder reference to the item so that its class can be determined.
            if (class of item this_item is folder) then
                try
                    -- Make new folders in this dropped folder. If you want to be able to have subfolders created for any of your structure you would have to list as shown below
                    set ART_Folder to (make new folder in this_item with properties {name:"Artwork"})
                    set Data_Folder to (make new folder in this_item with properties {name:"Data Processing"})
                    set Agency_Folder to (make new folder in ART_Folder with properties {name:"AGENCY"})
                    -- The below shows subfolders and how to input if you want additional folders inside of folders
                    make new folder in ART_Folder with properties {name:"EXPORT_TO_XMPIE"}
                    make new folder in ART_Folder with properties {name:"XMPIE"}
                    make new folder in Data_Folder with properties {name:"Data In"}
                    make new folder in Data_Folder with properties {name:"Data Released"}
                    make new folder in this_item with properties {name:"Imaging_Laser"}
                    make new folder in this_item with properties {name:"Production Report"}
                    make new folder in this_item with properties {name:"Program Plan"}
    
                    -- Move the items from the dropped folder to the just-created "AGECNY" folder.
                    move (every file of this_item) to Agency_Folder
                    move (every folder of this_item whose name is in {"Links", "Lowres PDFs"}) to Agency_Folder
                    move (every folder of this_item) to Agency_Folder
    
    
    
                on error errMsg
                    display dialog errMsg and (say "error")
                end try
            end if
        end tell
    end repeat
    end adding folder items to
    

    我在回答中解释了为什么你的脚本不能工作。我删除了答案,因为你完全忽略了我的建议。瓦迪安-我实际上试过你的脚本,但它对我不起作用。我照样复制粘贴,根本没有处理文件。这根本不是你干的。我感谢任何人和每个人的时间。我使用的是操作系统Sierra,我相信当涉及到Applescript时,该操作系统中存在一些错误
    on adding folder items to this_folder after receiving added_items
    -- added_items is a _list_ of the items just added, even when there's only one. Deal with each item in turn.
    repeat with this_item in added_items
        tell application "Finder"
            -- 'item this_item' gets a Finder reference to the item so that its class can be determined.
            if (class of item this_item is folder) then
                try
                    -- Make new folders in this dropped folder. If you want to be able to have subfolders created for any of your structure you would have to list as shown below
                    set ART_Folder to (make new folder in this_item with properties {name:"Artwork"})
                    set Data_Folder to (make new folder in this_item with properties {name:"Data Processing"})
                    set Agency_Folder to (make new folder in ART_Folder with properties {name:"AGENCY"})
                    -- The below shows subfolders and how to input if you want additional folders inside of folders
                    make new folder in ART_Folder with properties {name:"EXPORT_TO_XMPIE"}
                    make new folder in ART_Folder with properties {name:"XMPIE"}
                    make new folder in Data_Folder with properties {name:"Data In"}
                    make new folder in Data_Folder with properties {name:"Data Released"}
                    make new folder in this_item with properties {name:"Imaging_Laser"}
                    make new folder in this_item with properties {name:"Production Report"}
                    make new folder in this_item with properties {name:"Program Plan"}
    
                    -- Move the items from the dropped folder to the just-created "AGECNY" folder.
                    move (every file of this_item) to Agency_Folder
                    move (every folder of this_item whose name is in {"Links", "Lowres PDFs"}) to Agency_Folder
                    move (every folder of this_item) to Agency_Folder
    
    
    
                on error errMsg
                    display dialog errMsg and (say "error")
                end try
            end if
        end tell
    end repeat
    end adding folder items to