【问题标题】:Automatically move files of a certain type from folder A to B whenever they are added to folder A on macOS在 macOS 上将特定类型的文件添加到文件夹 A 时,自动将它们从文件夹 A 移动到 B
【发布时间】:2020-04-09 08:58:30
【问题描述】:

使用 Automator,我创建了一个“文件夹操作”,以便在将某些类型的文件(即“Kind IS Movie”)添加到文件夹“FolderA”后立即将它们从文件夹“FolderA”移动到文件夹“FolderB”。它工作正常,只是它不会从子文件夹中移动文件(例如,如果将电影文件添加到“FolderA/SubA/”则不起作用),并且显然 Automator 上没有选项可以使其在子文件夹上工作。

有没有人知道如何在 Automator 上更改它或者我如何为此创建一个脚本?谢谢!

【问题讨论】:

  • 你可以看看fswatch,你可以用homebrew安装。
  • 文件夹操作特定于特定文件夹,因此您需要将其附加到您希望它处理的每个文件夹。有关 AppleScript 示例,请参阅 this answer

标签: bash macos shell automator


【解决方案1】:

下面的 AppleScript 文件夹操作代码应该让您大致了解如何完成您正在寻找的内容。当将文件或文件夹添加到此文件夹操作所附加到的文件夹中时,它将搜索所有文件夹和子文件夹中的文件(我使用 QuickTime 电影作为文件类型......但您可以将其更改为您想要的任何内容) 然后这些文件将被移动到您将在 property moveToFolder 中定义的文件夹中

您可以将 Script Editor.app 中的以下代码作为 .scpt 文件直接保存到您的 /Users/Your_User_Name/Library/Workflows/Applications/Folder Actions 文件夹中。将脚本保存到该文件夹​​后,即可使用“文件夹操作设置”将其作为文件夹操作附加到任何文件夹。

-- Set This To The Folder You Want Your Videos Moved To
property moveToFolder : (path to desktop as text) & "moved_videos"
-- Set This To The Kind Of File To Act Upon
property fileKind : "QuickTime movie"

on adding folder items to theFolder after receiving theNewItems
    tell application "Finder"
        set movieFilesRef to a reference to (files of entire contents of folder theFolder ¬
            whose kind is fileKind)
        move movieFilesRef to alias moveToFolder
    end tell
end adding folder items to

或者这里是一个版本,它定义了要操作的文件的扩展名

-- Set This To The Folder You Want Your Videos Moved To
property moveToFolder : (path to desktop as text) & "moved_videos"
-- Set This To The Name Extensions Of Files To Act Upon
property videoFileExtensions : {"m4v", "mkv", "avi", "mp4", "mov", "wmv", "mpg"}

on adding folder items to theFolder after receiving theNewItems
    tell application "Finder"
        set movieFilesRef to a reference to (files of entire contents of folder theFolder ¬
            whose name extension is in videoFileExtensions)
        move movieFilesRef to alias moveToFolder
    end tell
end adding folder items to

【讨论】:

    猜你喜欢
    • 2011-07-22
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2015-09-29
    • 2019-06-20
    • 1970-01-01
    相关资源
    最近更新 更多