1

我想创建一个自动化操作来帮助管理 DNG/XMP 文件。我希望能够将 DNG(或多个)拖到将 DNG 和匹配的 XMP 文件发送到垃圾箱的操作上。除了扩展名之外,这些文件具有相同的名称,它们位于同一目录中。例如,IMGP1361.DNG 和 IMGP1361.xmp

对于 shell 脚本来说,这将是一项简单的任务,但是是否有 Automator 方法可以做到这一点(以了解有关 Automator 的更多信息)?有没有办法获取输入查找器项目的文件名,在变量中更改它并将其用作另一个操作的输入?

谢谢。

4

2 回答 2

2

Automator 的此脚本将删除所有具有相同前缀且名称扩展名列在 grep 命令中的文件。您也可以添加其他扩展。(xmp|DNG|pdf|xls)

on run {input, parameters}
try
    repeat with anItem in input
        tell (info for anItem) to set {theName, theExt} to {name, name extension}
        set shortName to text 1 thru ((get offset of "." & theExt in theName) - 1) of theName
        tell application "Finder"
            set parentFolder to parent of anItem as alias
            set matchList to every paragraph of (do shell script "ls " & POSIX path of parentFolder & " | grep -E '" & shortName & ".(xmp|DNG)'")
            delete (every file of parentFolder whose name is in matchList)
        end tell
    end repeat
end try
end run
于 2012-03-12T12:06:55.947 回答
1

好的,我知道了。您可以在 Automator 工作流程中使用下面给出的 AppleScript,如下所示:

自动化工作流程

对于 Finder 中的每个选定文件,如果其扩展名为 . ext_list,则它将被移至回收站,同一文件夹中的所有其他同名文件也将移至also_these_extensions.

它可能很有用,例如还可以用于清理带有辅助 LaTeX 文件的文件夹:只需将所有其他扩展名(例如)"tex"放入.ext_list"aux", "dvi", "log"also_these_extensions

选定的文件不需要在同一个文件夹中;您还可以在 Spotlight 搜索结果窗口中选择多个项目。

on run {input, parameters}
    -- for every item having one of these extensions:
    set ext_list to {"dng"}
    -- also process items with same name but these extensions:
    set other_ext_list to {"xmp"}

    tell application "Finder"
        set the_delete_list to {}
        set delete_list to a reference to the_delete_list
        -- populate list of items to delete
        repeat with the_item in input
            set the_item to (the_item as alias)
            if name extension of the_item is in ext_list then
                copy the_item to the end of delete_list
                set parent_folder to (container of the_item) as alias as text
                set item_name to text 1 thru ((length of (the_item's name as text)) - (length of (the_item's name extension as text))) of (the_item's name as text)
                repeat with ext in other_ext_list
                    try
                        copy ((parent_folder & item_name & ext) as alias) to the end of delete_list
                    end try
                end repeat
            end if
        end repeat
        -- delete the items, show info dialog
        move the_delete_list to the trash
        display dialog "Moved " & (length of the_delete_list) & " files to the Trash." buttons {"OK"}
    end tell
end run
于 2012-03-12T11:29:01.123 回答