【问题标题】:Applescript to Create Watch Folder and move files within dropped files and created foldersApplescript 创建监视文件夹并在删除的文件和创建的文件夹中移动文件
【发布时间】:2017-03-24 13:53:12
【问题描述】:

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

问题:

  1. 想要在数据处理文件夹中创建子文件夹,新名称将是 {"Data In", "Data Released"};这通常表示我在尝试执行此操作时没有定义变量
  2. 我希望将放置文件夹中的所有文件和文件夹移动到 Artwork 文件夹下的 AGENCY 文件夹中;如果我尝试不执行上述 #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

=======Vadian 在被删除之前提供的答案=========

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

*

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

*

    on adding folder items to this_folder after receiving added_items
repeat with this_item in added_items
    tell application "Finder"
        if (class of this_item is folder) then
            set allItems to every item of this_item
            do shell script "mkdir -p " & quoted form of POSIX path of this_item & "{Artwork/{AGENCY,EXPORT_TO_XMPIE,XMPIE},'Data Processing'/{'Data In','Data Released'},Imaging_Laser,'Production Report','Program Plan'}"
            -- Move the following items from the dropped folder to the just-created "AGECNY" folder.
            move allItems to folder "Artwork:AGENCY:" of this_item
        end if
    end tell
end repeat
end adding folder items to

【问题讨论】:

  • 我在回答中解释了为什么您的脚本无法运行。我删除了答案,因为您完全忽略了我的建议。
  • Vadian - 我实际上尝试了您的脚本,但它对我不起作用。我照原样复制并粘贴它,根本没有处理文件。这根本不是你。我感谢任何人和每个人的时间。我正在使用 OS Sierra,我相信在 Applescript 方面该操作系统存在一些错误

标签: applescript


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2021-03-14
    • 1970-01-01
    相关资源
    最近更新 更多